approxRatio and Ratio Word

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

approxRatio and Ratio Word

Vilem-Benjamin Liepelt-2
I have been experiencing curious behaviour with approxRatio:

Prelude Data.Ratio> let a = 0 :: Word
Prelude Data.Ratio> let b = 10 :: Word
Prelude Data.Ratio> a%b
0 % 1
Prelude Data.Ratio> approxRational (a%b) 0.01
1 % 1
Prelude Data.Ratio> approxRational (0%1) 0.01
0 % 1

Is this expected? If so, why?
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: approxRatio and Ratio Word

ALeX Kazik
> Is this expected? If so, why?

Yes, that is expected.
The approxRational calculation is based on x+eps and x-eps, which is
1%100 and 3689348814741910323%20 in your example, and the last one is
due to the fact that there are no negative numbers in word and there
is a silent underflow. (similar to: (0::Word)-1).
And the simplest rational number between these two is 1.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.