You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Both big.Int and big.Rat have MarshalText and UnmarshalText methods to implement two interfaces from encoding package: TextMarshaler and TextUnmarshaler.
big.Float should implement these interfaces as well
The text was updated successfully, but these errors were encountered:
Implementing these interfaces is less trivial than it seems.
Fast and looseless implementation could use hexadecimal notation with 'p' (binary) exponent. But it depends about the expectations of MarshalText: Should it always return a string representation that is a "standard" floating-point number that might be read by another system? In that case, the 'p' notation might not be option.
An implementation that is more similar to float32/64 can use 'g' with precision -1 (once implemented) but it's a very expensive conversion. Additionally currently there is no way to parse a string without loosing precision. Parse's semantic may actually not be correct as is: It perhaps should parse w/o rounding error if the precision is 0.
Decided to keep it simple for now and implement this simply via the 'g' with precision -1 format. Also, no recording of precision or accuracy. This makes this work for json w/o trouble.
Both
big.Int
andbig.Rat
haveMarshalText
andUnmarshalText
methods to implement two interfaces fromencoding
package:TextMarshaler
andTextUnmarshaler
.big.Float
should implement these interfaces as wellThe text was updated successfully, but these errors were encountered: