qorelanguage / qore

Qore Programming Language
GNU General Public License v2.0
61 stars 10 forks source link

Comparison operators for numbers and floats do not handle @nan@ correctly #915

Closed tethal closed 8 years ago

tethal commented 8 years ago

For more details see comments in #910

From mpfr_cmp documentation:

If one of the operands is NaN, set the erange flag and return zero.

Qore ignores the erange flag and interprets the zero return value as 'equal' (qore_number_private.h:261)

tethal commented 8 years ago

float version of the operators do not work either:

printf("%s\n", @nan@ < 1.0);
printf("%s\n", @nan@ <= 1.0);
printf("%s\n", @nan@ == 1.0);
printf("%s\n", @nan@ != 1.0);
printf("%s\n", @nan@ === 1.0);
printf("%s\n", @nan@ !== 1.0);
printf("%s\n", @nan@ > 1.0);
printf("%s\n", @nan@ >= 1.0);

Produces (all should be False):

0
1
0
1
0
1
0
1
tethal commented 8 years ago

As part of this issue, we should also check:

tethal commented 8 years ago

Also:

qore -nX '1 == @nan@n'
True
qore -nX '1.0 == @nan@n'
True