"John Randall" <[EMAIL PROTECTED]> wrote: >>> a=:!19 >>> 3!:0 a >>> 8 NB. floating point >>> b=:!x:19 >>> 3!:0 b >>> 64 NB. extended integer >>> >>> So in principle x: 4*a is rational, not an integer. >> >> I don't see how this follows. 4*a is a floating-point number >> which is exactly equal to 486580401635328000. When I convert >> that to exact, I could see that it might become a fraction >> equal to 486580401635328000, or it could become the integer >> 486580401635328000. >> Here it becomes a fraction that has some other value, which >> I don't understand. >> > > (I am on a 32-bit machine. Things may be different for 64 bits.)
This is likely a key point. The expression !19, since 19 is an integer, should produce an integer result (which it does in a 64-bit environment). Regrettably, 32-bit integers are too small for this, so J gracefully degrades to floating point there. > I don't see why a should be exactly an integer. If you assume it has been > calculated in the most favorable manner, so that powers of 2 can be moved > into the characteristic, it would still have a mantissa of size 40, more > than the 23 bits allowed for IEEE 32-bit numbers, making exact > representation impossible. Whatever the details, x: !n is eventually > going to give a fraction. 2^.!19 56.7555 +/2 = q: !19x 16 So !19 requires 57 bits to store, but the last 16 of those are zero, so there are only 41 significant bits, well under the 53 that can be stored in IEEE 64-bit real numbers, which J uses. So even !19 though it is represented by a floating-point value, the representation is that of an integer, and it is exactly equal to !19. 4*!19 will produces eactly the same result, with +2 to the characteristic. Loss of precision in a representation only matters if you have to change the value in order to lower the precision. For example, if you want to represent 3.14159 to only two decimal places, you use 3.14 (and the error is .00159, around 1 part in 2000). However, if you want to represent 5.00000 to two decimal places, you get 5.00 which is exactly the same, since discarding trailing zeroes does not change the result in the slightest. That is what is happening with 4*!19. -- Mark D. Niemiec <[EMAIL PROTECTED]> ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
