>>  <<  Usr  Pri  JfC  LJ  Phr  Dic  Voc  !:  Help  Primer


This section is a bit advanced and understanding it is not critical. If it makes sense, great. If not, don't worry about it, and just move on to the next section.

For some kinds of work with floating point numbers, this section is important, along with a more detailed understanding of how numbers are stored and manipulated by the hardware. For most work, however, this section can be ignored.

Let's consider the calculation at the end of the last section in more detail.
   pps 20
   a =. 3 * 100 * % 3
   a = 100
By exact math you would expect a to be 100. But because the computer can't exactly represent the value %3, you get a value for a that is very close to 100, but not exactly, as you can see by its detailed display with a print precision of 20. However, note that a is considered to be equal to 100, even though you can see that it is not exactly equal. This is because the comparison is tolerant. That is, numbers do not have to be exactly identical to be considered equal.

Let's experiment to get an idea for how tolerant the comparison is by gradually taking the value further away from 100. The input line recall shortcut with Shift+Ctrl+up arrow is very useful for playing with things like this.
   100 = 100
   100 = 99.999999999999986
   100 = 99.99999999999998
   100 = 99.9999999999999
   100 = 99.999999999999
   100 = 99.99999999999
In the last example you crossed the line and the value is far enough away from 100 that it is no longer considered to be equal. Let's look at another example.
   a =. 23
   b =. a - 1e_12
   c =. a - 1e_11
   a = b
   a = c
The values of a and b are close enough to be considered equal. The values of a and c are not close enough to be considered equal. Close enough refers to the difference between the two numbers.
   a - b
   a - c
In both cases the difference is small, but b is closer than c to a. Reading the J Dictionary definition for = you will see that the dividing line between close enough and not close enough is determined by the result of multiplying the larger of the numbers times the default tolerance value of 2^_44. That is, close enough is relative to the size of the numbers.
   tolerance =. a * 2 ^ _44
Check both differences against this tolerance:
   (a - b , c) <: tolerance
1 0
The difference between a and b is less or equal to the tolerance, whereas the difference between a and c is not.

>>  <<  Usr  Pri  JfC  LJ  Phr  Dic  Voc  !:  Help  Primer