Jakob,

Thank you. I knew I had to be missing some nuance of how to use the library 
correctly.

Thanks,
Anthony

On Wednesday, April 18, 2018 at 1:44:13 AM UTC-7, Jakob Borg wrote:
>
> That is a much too large value to be precisely represented by a float64. 
> You need more bits, and you need to tell big.Float how many bits that is: 
>
> *https://play.golang.org/p/btm6-_9NQgB 
> <https://play.golang.org/p/btm6-_9NQgB>*
>
> //jb
>
> On 18 Apr 2018, at 09:57, agru...@gmail.com <javascript:> wrote:
>
> I have been playing with the karatsuba algorithm and was doing some 
> testing testing to compute the correct values of two large numbers 
> 3141592653589793238462643383279502884197169399375105820974944592 
> and 2718281828459045235360287471352662497757247093699959574966967627. 
> When working with the math/big package I noticed this oddity, I am sure I 
> am doing something wrong but hopefully someone can help point it out. If 
> notice from below the value out of big.NewFloat(myFloat) does not match the 
> value from printing out g. It also does not match if I print using 
> g.Float64() and then print the value from that. Should not this be the same 
> thing in and the same thing out? Thanks in advance. 
>
> // 
> 8539734222673567065463550869546574495034888535765114961879601127067743044893204848617875072216249073013374895871952806582723184
>  
> - correct
>     // 
> 8539734222673566930176750436921930623970378254642185393758656420093500067115747270318696482879857934897660315084890343252951040
>  
> - incorrect but this is what I get with the big.NewFloat().Mul
>
>     f := big.NewFloat(float64(
> 3141592653589793238462643383279502884197169399375105820974944592)) 
> //.SetPrec(9223372036854775807) 
> //.SetMode(big.ToZero)
>     g := big.NewFloat(float64(
> 2718281828459045235360287471352662497757247093699959574966967627)) 
> //.SetPrec(9223372036854775807) 
> //.SetMode(big.ToZero)
> 2718281828459045271981924443963747209279784634148078442319446016.000000 
> this is what g prints vs what was input
>
>     h := big.NewFloat(1).Mul(f, g).SetPrec(9223372036854775807) 
> //.SetMode(big.ToZero)
>
>     a := float64(
> 3141592653589793238462643383279502884197169399375105820974944592) * 
> float64(2718281828459045235360287471352662497757247093699959574966967627)
>
>     fmt.Printf("%f\n", f)
>     fmt.Printf("%f\n", g) //prints out 
> 2718281828459045271981924443963747209279784634148078442319446016.000000
>     fmt.Printf("%f\n", a)
>     fmt.Printf("%f\n", h)
>
> -- 
> 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...@googlegroups.com <javascript:>.
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to