On Sun, Feb 14, 2021 at 9:20 PM Santhosh Kumar T <santhosh.tek...@gmail.com> wrote:
> I created: > one instance using big.NewFloat function > another instance using big.Float.SetString method > > Adding to this: Generally, comparing FP values for equality can give results you don't expect due to the way numerics for floating point values work. They almost behave like normal numbers. In particular, you would like laws such as (x + y) + z = x + (y + z) (x * y) * z = x * (y * z) to hold (which are the associative laws from math). But for floating point numbers they don't due to rounding errors. Equality tests can also feel, as you see. I know that the original problem is one about parsing, so the underlying representation isn't the same. But if you want to compare floating point numbers for equality it is often better to define a small epsilon constant as something like 1e-06 or such and then compare if |x - y| < epsilon. For background, there are some good documents on the net about numerics of FP. http://https://floating-point-gui.de/ is one such resource. If you want the deep in-depth treatment I can recommend Knuth's "The Art of Computer Programming Vol 2: Seminumerical Algorithms". -- 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/CAGrdgiU0AgN8r4JbRX-OXAGhVGgTQG5OnU7R-fgwwTJximT2WA%40mail.gmail.com.