approxRatio and Ratio Word

4 Nov
2017
4 Nov
'17
6:04 p.m.
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?

4 Nov
4 Nov
7:06 p.m.
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.
2756
Age (days ago)
2756
Last active (days ago)
1 comments
2 participants
participants (2)
-
ALeX Kazik
-
Vilem-Benjamin Liepelt