Print precision

From J Wiki
Jump to navigation Jump to search


<=   =>

Print precision is the number of digits shown when a number is displayed.

   1 % 3
0.333333
   10 % 3
3.33333
   100 % 3
33.3333


Using lists and some of the new primitives you can now see this more concisely:

   (10 ^ i. 6) % 3
0.333333 3.33333 33.3333 333.333 3333.33 33333.3


You can guess that the default print precision is 6 because in each case 6 digits are shown.

   a =. 1e5 + 10 % 3
   b =. a + 0.1
   a
100003
   b
100003
   a = b
0


With only 6 digits shown, a and b look the same even though they aren't. In a situation like this you need to see more digits. The print precision can be changed by use of the following verb.

   pps =. 9!:11	NB. print precision set


Don't worry about the curious appearance of this verb, just use it.

   pps 9
   a
100003.333
   b
100003.433


With print precision of 9 there is enough detail to see what is going on.

   pps 6
   %3 9 13
0.333333 0.111111 0.0769231
   pps 12
   %3 9 13
0.333333333333 0.111111111111 0.0769230769231


The default print precision of 6 is adequate for most situations because you don't usually have to see all those extra digits of detail. However, it is important to know that they really are there, and that the display has been abbreviated as a matter of convenience.

<=   =>

Primer Index               Hover to reveal titles   -   Click to access   -   Current page is highlighted
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
45 46 47 48
50 51 52 53 54 55 56 57
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
97 98 99 100 101 102 103 104 105 106