package bigfft
import (
"math/big"
)
func FromDecimalString (s string ) *big .Int {
var sc scanner
z := new (big .Int )
sc .scan (z , s )
return z
}
type scanner struct {
powers []*big .Int
}
func (s *scanner ) chunkSize (size int ) (int , *big .Int ) {
if size <= quadraticScanThreshold {
panic ("size < quadraticScanThreshold" )
}
pow := uint (0 )
for n := size ; n > quadraticScanThreshold ; n /= 2 {
pow ++
}
return quadraticScanThreshold << (pow - 1 ), s .power (pow - 1 )
}
func (s *scanner ) power (k uint ) *big .Int {
for i := len (s .powers ); i <= int (k ); i ++ {
z := new (big .Int )
if i == 0 {
if quadraticScanThreshold %14 != 0 {
panic ("quadraticScanThreshold % 14 != 0" )
}
z .Exp (big .NewInt (1e14 ), big .NewInt (quadraticScanThreshold /14 ), nil )
} else {
z .Mul (s .powers [i -1 ], s .powers [i -1 ])
}
s .powers = append (s .powers , z )
}
return s .powers [k ]
}
func (s *scanner ) scan (z *big .Int , str string ) {
if len (str ) <= quadraticScanThreshold {
z .SetString (str , 10 )
return
}
sz , pow := s .chunkSize (len (str ))
s .scan (z , str [:len (str )-sz ])
left := Mul (z , pow )
s .scan (z , str [len (str )-sz :])
z .Add (z , left )
}
const quadraticScanThreshold = 1232
The pages are generated with Golds v0.3.6 . (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .