Thanks for bringing this up. It surprised me too until I realised what was going on.
The issue here is about the default precision that you're getting for those big.Float values. When you use big.NewFloat, the precision you get is exactly the same as that of a base64 float (53 bits). When you use SetString, you're getting 64 bits. If you change both float values to use the same precision, you'll see a difference in representation: https://play.golang.org/p/4tBpBsPgGtE This is documented, although arguably not that easy to find: For the precision used by big.NewFloat: NewFloat allocates and returns a new Float set to x, with precision 53 For the precision set by SetString: If z's precision is 0, it is changed to 64 before rounding takes effect. For the string output when used with fmt.Print: The 'v' format is handled like 'g'. > A negative precision selects the smallest number of decimal digits > necessary to identify the value x uniquely using x.Prec() mantissa bits. Actually I don't think the docs explicitly say that a missing precision for %g is treated as a negative precision passed to the Text method, which could be considered a flaw in the docs. One other thing to be aware of: the String method doesn't do quite what you might expect: https://github.com/golang/go/issues/42887 cheers, rog. On Sun, 14 Feb 2021 at 21:33, Santhosh Kumar T <santhosh.tek...@gmail.com> wrote: > now I understand it. why they are not same > > but why f2 printed as 123.40000000000000000139 > f2 is constructed using SetString method, so it should be accurate and > printed as 123.40000000000000000000. > > - Santhosh > > On Monday, February 15, 2021 at 2:53:45 AM UTC+5:30 kortschak wrote: > >> On Sun, 2021-02-14 at 13:19 -0800, Santhosh Kumar T wrote: >> > When I print both values, they print exactly same. so I am assuming >> > no precision lost for this specific example 123.4. >> > but still Cmp returns non-zero. >> >> This is not a good assumption to make, and is refuted by the result of >> Cmp. >> >> https://play.golang.org/p/ROr6cHMzWIf >> >> >> >> >> -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/b6a82206-6660-4a08-85bd-86e482b8527en%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/b6a82206-6660-4a08-85bd-86e482b8527en%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAJhgacg-ZzDSupwS%2BaXdKfoCWveHvsT8NnDUVmo8NpD8sY6McA%40mail.gmail.com.