Dave, try this version: https://play.golang.org/p/p5zyQF1Sdr

 

From: <[email protected]> on behalf of Jan Mercl <[email protected]>
Date: Monday, October 10, 2016 at 4:40 PM
To: Dave Cohen <[email protected]>, golang-nuts 
<[email protected]>
Subject: Re: [go-nuts] big.Rat anomalies

 


On Mon, Oct 10, 2016 at 4:29 PM Dave Cohen <[email protected]> wrote:

> numerator.SetFloat64(118.5285714285714) // becomes 
> 118.528571428571396495499357115477
> big.NewRat(592642857142857, 5000000000000) // becomes 
> 118.528571428571400000000000000000 - more accurate than SetFloat64 above!
>
> So my first question is why is SetFloat64() less accurate than the ratio used 
> in NewRat() above?

 

A float64 number has only 53 bits of mantissa precision while the result of 
big.NewRat is always exact (has infinite precision).

 

-- 

-j

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

Reply via email to