bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] Fuzzy Floor and Ceiling


From: Juergen Sauermann
Subject: Re: [Bug-apl] Fuzzy Floor and Ceiling
Date: Fri, 14 Aug 2015 18:32:12 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.4.0

Hi,

I have analyzed this issue a little and the following was my conclusion.

1. when looking at the GNU APL code I found that it could be simplified a little and I did that, SVN

2. It is perfectly correct that, as Jay pointed out, ⎕CT is nowadays a relative number. However in the
 context ofand it is relative to 1 ( resp. compute the (positive) distance D between, say, B and ⌈B resp. ⌊B and
then D is checked for being close (i,.e. within ⎕CT) to 1 or not in order to decide if B shall be
rounded up or down) so that it is practically absolute.

The language of the ISO standard is a little hard to grasp, but what I am getting from it is this (for real numbers):
Let R be a real number between Integers N-1 and N. Then ⌊R is N for R ≥ N-⎕CT and N-1 otherwise. ⌊R follows suit.

So in theory
⌊5-⎕CT should be 5 as Mike expected. However, what really happens is this: when computing
5-⎕CT (or N-⎕CT in the general case) then, due to rounding errors, the result is sometimes lower than N-⎕CT and
sometimes higher. For example, in GNU APL we have:

      ⌊ (⍳10) - ⎕CT
0 2 3 4 4 5 6 7 9 10


Some numbers are rounded up and some are rounded down. In general one can say that the behavior of and
at their border between rounding up or down is undefined.

I also tried IBM APL2, which seemed to do it right, but only because they do NOT follow the standard:

      ⌊ (⍳10) - ⎕CT
0 2 3 4 5 6 7 8 9 10


But then:


        ⌊ 5 - ⎕CT×⍳10
5 5 5 5 4 4 4 4 4 4

        ⌊ 8 - ⎕CT×⍳10
8 8 8 8 8 8 8 7 7 7

      ⌊ (⍳10) ∘.- ⎕CT×⍳10
 0  0  0  0  0  0  0  0  0 0
 2  1  1  1  1  1  1  1  1 1
 3  3  2  2  2  2  2  2  2 2
 4  4  4  3  3  3  3  3  3 3
 5  5  5  5  4  4  4  4  4 4
 6  6  6  6  6  5  5  5  5 5
 7  7  7  7  7  7  7  6  6 6
 8  8  8  8  8  8  8  7  7 7
 9  9  9  9  9  9  9  9  8 8
10 10 10 10 10 10 10 10 10 9


That suggest that IBM APL2 sets the border between rounding up or down at N+N×⎕CT instead
N+⎕CT. As far as I can see, this is correct in other places (like comparison of numbers) but not for and .

Summary: For and GNU APL follows the ISO standard while IBM APL2 does not.

/// Jürgen


On 08/12/2015 10:04 AM, Jay Foad wrote:
I don't know anything about the GNU APL implementation, but I can tell
you that the definition of tolerant-floor changed between standard APL
(ISO 8485) and Extended APL (ISO 13751). In ISO 8485 the tolerance is
relative, so both your examples should definitely return 5. In
Extended APL the tolerance is absolute, so both your examples are
right on the cusp of whether they should return 5 or the next integer
up/down.

Jay.

On 12 August 2015 at 03:25, Mike Duvos <address@hidden> wrote:
      ⌊5-⎕CT
4

      ⌈5+⎕CT
6


Unless something has drastically changed since I last read the APL spec,
both of these should return 5.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]