Talk:Convert decimal number to rational: Difference between revisions

(→‎J and best fit: new section)
Line 38:
 
This is a curiosity rather than critism, because I know nothing about J to begin with. My question: how is a floating point stored in J, and how does it determine what a "best fit" is? In the first example 0.518518 turned into a "866492568306r1671094481399" ("r" means "/" I assume?). Why? What about 518518/1000000? --[[User:Ledrug|Ledrug]] 17:57, 14 June 2011 (UTC)
:I believe J floats are bog standard ieee floats which means just under 16 decimal digits of precision. And, yes, r means ratio -- it's the first integer divided by the second integer. As for 866492568306 divided by 1671094481399, when you divide that out and compare 866492568306 with 866492568305 and 866492568307, you have to drop down to 11 digits of precision to before the +1 and -1 versions look identical. That means that 866492568306 is roughly accurate to 12 digits of precision. In other words, we might be ignoring up to 16 trailing binary digits with that answer (and apparently the algorithm being used in that version of J apparently requires that we keep over 10 digits of precision).
:I have not studied this matter very closely, but this seems like it is related to the way J checks for equality on floating point numbers:
:J uses an epsilon which is scaled by the value with the largest magnitude when checking for equality . The idea is that floating point numbers that are meant to be equal are usually quite close. In other words, when the difference between the two floating point values is less than (in the default case) 2^-44 times the larger magnitude value they are "equal". This does not always do the right thing (floating point subtraction can get awful), and can be turned off when the programmer is prepared to deal with proper numerical analysis, but it's usually the right thing to do when using an algorithm that cares about equality in the context of floating point numbers. --[[User:Rdm|Rdm]] 20:30, 14 June 2011 (UTC)
6,951

edits