Re: Numeric problem in BlackBox 1.4

From: [at]} <Wojtek>
Date: Mon, 17 Feb 2003 13:20:18 -0500 (EST)

----boundary-LibPST-iamunique-537276894_-_-
Content-type: text/plain

Hello:

 Tech Support (Marc) answered:

> The exact value of 1.000000000000000001 can't be stored
> in a variable of type REAL. That's why the compiler truncates
> this number to r = 1.0 in the assignment r := 1.000000000000000001.
> You can check this in the debugger by inserting a HALT statement
> after the assignment.

On the other hand, Dominik Gruntz wrote:

> The REAL variable is not rounded in any way, but rather the int
> (or long) is converted to a REAL, in this example without loss of
> precision (as the integer 1 can be represented exactly as REAL).
> The comparison is then performed between two real numbers,
> and I would expect that the tests both either return true or false.

I think that these two answers neatly illustrate the confusion.
Dominik, who is definitely a better expert than I am, expects
both cases to be consistent. IMHO this makes sense. Why should
I have to count the digits in the source code, or HALT the program,
in order to disentangle the confusing case?

On the other hand, Marc's technical explanation also makes sense.
The comparison has to be made somehow. It makes more sense to promote
the integer type to the f.p. type, than to truncate the f.p. type.
This makes the result of the comparison implementation-dependent.
The outcome cannot be easily understood by just reading the program.
Furthermore, I have not found this explained in the Language Report
under the section "8.2.5 Relations".

I repeat my question. Is this confusion warranted, or should rather
the implementation of the compiler be tightened up such that an
explicit type cast would be required for the relations. In other words,
the relation (realVar = intVar) would not compile? Is this a sensible
solution, or should it rather be left open for implementers?

In any case, I propose that an explanation is added to the Language
Report to make it clear. It would also make sense to include the
particular example that I provided.

In case OuS does not want to edit the Report in a significant way,
how about adding a hyperlink entitled "A clarifying example concerning
mixed-type comparisons". You guys have implemented hyperlinks in the
BlackBox. How about using them now to add clarifications to your
documentation, which is not always entirely clear?

Thank you,

Wojtek

> >
> > the following code illustrates a numeric problem with CP
> > compiler, version BlackBox 1.4 unpatched. The comparison
> > yields either TRUE or FALSE depending on the precision
> > of the REAL number. (Try exchanging the order of the
> > lines where the REAL variable is assigned). The language
> > report does not say anything about such a mixed comparison
> > (realVar = intVar). In the spirit of robustness I would
> > rather prefer that this expression does not compile at all.
> > ENTIER should be necessary, rather than relying on
> > rounding the REAL variable in some implicit way.
> >
> > Excuse me if this was already patched.
> >
> > Wojtek Skulski skulski{([at]})nowhere.xy
> >
> > MODULE TestEqual;
> > IMPORT StdLog;
> > PROCEDURE Test*;
> > VAR
> > tst: BOOLEAN;
> > r: REAL; long: LONGINT; int: INTEGER;
> > BEGIN
> > long := 1; int := 1;
> > r := 1.000000000000000001; (* TRUE*)
> > r := 1.0000000000001; (* FALSE*)
> > tst := (r = long);
> > StdLog.String("Real = long: ");
> > StdLog.Bool (tst); StdLog.Ln;
> > tst := (r = int);
> > StdLog.String("Real = int: ");
> > StdLog.Bool (tst); StdLog.Ln;
> > END Test;
> > END TestEqual.
> >
> > TestEqual.Test
> >

--------------------------------------------

To unsubscribe from this mailing list, send a message containing the word "unsubscribe" to:
   blackbox-request{([at]})nowhere.xy

To get a list of valid e-mail commands and instructions on their usage, send a message containing the word "help" to the above address.

Send any problem reports or questions related to this email list to the list owner at
   owner-blackbox{([at]})nowhere.xy

Current posting policy:

a) To post you should use the same address by which you are subscribed to the mailing list. That way, the list server will recognize you as subscriber and forward your posting immediately, without creating any overhead.

b) If, for some reason, you cannot post from the address, by which you are subscribed, your message will be moderated to avoid spam. Please understand that moderation will often cause some delay, in particular over weekends or holydays.


----boundary-LibPST-iamunique-537276894_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"

e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQp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