bug-apl
[Top][All Lists]
Advanced

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

Re: [Bug-apl] Equals and not-equals operators for complex numbers yield


From: Elias Mårtenson
Subject: Re: [Bug-apl] Equals and not-equals operators for complex numbers yield wrong results.
Date: Mon, 20 Jan 2014 13:40:55 +0800

They do compare equal using ≡ though. Actually, all equals comparisons with complex numbers seems to be broken.

I fixed it by replacing the implementation of ComplexCell:bif_equal() (in ComplexCell.cc) with the following:

void ComplexCell::bif_equal(Cell * Z, const Cell * A) const
{
   const APL_Float qct = Workspace::get_CT();
   new (Z) IntCell(equal(*A, qct) ? 1 : 0);
}

This will leverage the standard comparison function which is much more robust.

Regards,
Elias


On 20 January 2014 06:51, Frederick H. Pitts <address@hidden> wrote:
Gentle people,

        In GNU APL 1.0, evaluating

        0J0 = 0J0

yields 0.  Replacing the equals operator with the not-equal operator and
re-evaluating yields 1.  Furthermore, evaluating

        0J0 = 0

yields 0.

        I discovered the above anomalies while attempting to write a regression
test for the encode operator.  When I attempted to compare the result of
encoding 4 in binary (i.e., 1 0 0) with 1 0 0 and then reducing with
logical and, I get 0.  That is because the two zeros in the result are
actually complex zeros and fail to compare for equality with the real
zeros in the expected answer.  Oddly enough, the leading 1 does compare
correctly.  Maybe the complex 1 demotes to real 1 and then integer 1
correctly while the complex zero does not.

        If the above behavior of complex/complex and complex/real compares for
equality/inequality is what is actually intended, the release notes and
user documentation should emphasize the fact.

        And if the above has been reported previously, please forgive my
intrusion.

Regards

Fred Pitts
Retired Chemical Engineer




reply via email to

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