Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

=== confused by subclassed NaN #5576

Closed
p6rt opened this issue Aug 19, 2016 · 4 comments
Closed

=== confused by subclassed NaN #5576

p6rt opened this issue Aug 19, 2016 · 4 comments
Labels
RFC Request For Comments

Comments

@p6rt
Copy link

p6rt commented Aug 19, 2016

Migrated from rt.perl.org#129002 (status was 'resolved')

Searchable as RT129002$

@p6rt
Copy link
Author

p6rt commented Aug 19, 2016

From zefram@fysh.org

I can vacuously subclass Num and instantiate my new class with specific
floating-point values, and this generally works. The subclassed numbers
correctly compare == and !=== to the base Num of the same floating-point
value​:

my $three = (my class MyNum is Num {}).new(3e0); say $three.WHICH; say $three == 3e0; say $three === 3e0
MyNum|3
True
False

But there's a problem with NaN. It correctly compares != to the base NaN
(per usual numeric comparison semantics, and correctly has a different
.WHICH reflecting its different class, but bizarrely it compares ===
to the base NaN​:

my $mynan = (my class MyNum is Num {}).new(NaN); say $mynan.WHICH; say $mynan == NaN; say $mynan === NaN
MyNum|NaN
False
True

=== on NaNs should pay attention to the class, in the same way that ===
on non-NaN Num values does.

-zefram

@p6rt
Copy link
Author

p6rt commented Dec 18, 2016

From @zoffixznet

On Fri, 19 Aug 2016 15​:40​:36 -0700, zefram@​fysh.org wrote​:

I can vacuously subclass Num and instantiate my new class with
specific
floating-point values, and this generally works. The subclassed
numbers
correctly compare == and !=== to the base Num of the same floating-
point
value​:

my $three = (my class MyNum is Num {}).new(3e0); say $three.WHICH;
say $three == 3e0; say $three === 3e0
MyNum|3
True
False

But there's a problem with NaN. It correctly compares != to the base
NaN
(per usual numeric comparison semantics, and correctly has a different
.WHICH reflecting its different class, but bizarrely it compares ===
to the base NaN​:

my $mynan = (my class MyNum is Num {}).new(NaN); say $mynan.WHICH;
say $mynan == NaN; say $mynan === NaN
MyNum|NaN
False
True

=== on NaNs should pay attention to the class, in the same way that

on non-NaN Num values does.

-zefram

Thank you for the report. This is now fixed.

I suspect it was fixed a while back, when issues with NaNs were sorted out.
Test added​: Raku/roast@860dc71980

@p6rt
Copy link
Author

p6rt commented Dec 18, 2016

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Dec 18, 2016

@zoffixznet - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Dec 18, 2016
@p6rt p6rt added the RFC Request For Comments label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request For Comments
Projects
None yet
Development

No branches or pull requests

1 participant