Categorygithub.com/stewi1014/modular
module
0.0.0-20231012024447-e3819b7b57bb
Repository: https://github.com/stewi1014/modular.git
Documentation: pkg.go.dev

# README

modular

A modular arithmetic library with an emphasis on speed Status

Float64 GoDoc

Float32 GoDoc

Modular tries to leverage pre-computation as much as possible to allow direct computation in Congruent() and Index(), using fastdiv and pre-computed lookup tables. I can't test it on all hardware, but in principle should perform better than traditional modulo functions on all but the strangest of hardware.

For example, on my machine with a modulo of 1e-25;

float64

NumberMath.ModModulus.CongruentIndexer.Index
014.1 ns/op6.07 ns/op12.4 ns/op
2.5e-2529.2 ns/op14.4 ns/op15.7 ns/op
1467 ns/op37.5 ns/op38.1 ns/op
1e3008063 ns/op36.3 ns/op39.4 ns/op

float32

NumberMath.ModModulus.CongruentIndexer.Index
015.6 ns/op5.49 ns/op11.3 ns/op
2.5e-2533.5 ns/op12.1 ns/op11.3 ns/op
1766 ns/op12.0 ns/op10.9 ns/op
1e251259 ns/op12.0 ns/op11.0 ns/op

I've use the name 'Congruent' as it's a more explicit definition of the function, and helps avoid confusion with other functions. It is the same as a euclidian 'modulo' function; that is, it finds the number satisfying '0 <= n < modulus' that is representative of the given number's congruency class, hence the name Congruent.

# Packages

No description provided by the author
No description provided by the author