Source File
ratconv.go
Belonging Package
math/big
var , int64
}
switch {
case 10:
+=
fallthrough // see fallthrough above
case 2:
+=
default:
panic("unexpected exponent base")
switch {
case 'e', 'E':
= 10
case 'p', 'P':
if {
= 2
break // ok
}
fallthrough // binary exponent not permitted
default:
.UnreadByte() // ch does not belong to exponent anymore
return 0, 10, nil
}
:= '.'
:= false
:= false
for == nil {
if '0' <= && <= '9' {
= append(, )
= '0'
= true
} else if == '_' && {
if != '0' {
= true
}
= '_'
} else {
.UnreadByte() // ch does not belong to number anymore
break
}
, = .ReadByte()
}
if == io.EOF {
= nil
}
if == nil && ! {
= errNoDigits
}
if == nil {
, = strconv.ParseInt(string(), 10, 64)
if == nil && ( || == '_') {
= errInvalSep
}
return
}
= .add(, )
if .b.abs.cmp() <= 0 {
= .add(, natOne)
if .cmp() >= 0 {
= nat(nil).add(, natOne)
= nat(nil).sub(, )
}
}
if .a.neg {
= append(, '-')
}
= append(, .utoa(10)...) // itoa ignores sign if q == 0
if > 0 {
= append(, '.')
:= .utoa(10)
for := - len(); > 0; -- {
= append(, '0')
}
= append(, ...)
}
return string()
![]() |
The pages are generated with Golds v0.3.2-preview. (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. |