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

Rat → Num conversion isn’t monotonous #6623

Closed
p6rt opened this issue Oct 20, 2017 · 6 comments
Closed

Rat → Num conversion isn’t monotonous #6623

p6rt opened this issue Oct 20, 2017 · 6 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Oct 20, 2017

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

Searchable as RT132329$

@p6rt
Copy link
Author

p6rt commented Oct 20, 2017

From @Grimy

How to reproduce


perl6 -e 'my ($a, $b) = (0.777777777777777777777,
0.7777777777777777777771); say $a <=> $b, " ", Num($a) <=> Num($b)'

Expected behavior


Prints `Less Less`, or `Less Same`, depending on how rounding is done.

Actual behavior


Prints `Less More`. This seems inconsistent​: $a is strictly smaller
than $b, yet Num($a) is strictly larger than Num($b).

Version information


This is Rakudo version 2017.09 built on MoarVM version 2017.09.1
implementing Perl 6.c.

This may be related to https://rt.perl.org/Public/Bug/Display.html?id=132313

@p6rt
Copy link
Author

p6rt commented Oct 21, 2017

From @zoffixznet

On Fri, 20 Oct 2017 07​:34​:04 -0700, victor.adam@​derpymail.org wrote​:

How to reproduce
----------------

perl6 -e 'my ($a, $b) = (0.777777777777777777777,
0.7777777777777777777771); say $a <=> $b, " ", Num($a) <=> Num($b)'

Expected behavior
-----------------

Prints `Less Less`, or `Less Same`, depending on how rounding is done.

Actual behavior
---------------

Prints `Less More`. This seems inconsistent​: $a is strictly smaller
than $b, yet Num($a) is strictly larger than Num($b).

Version information
-------------------

This is Rakudo version 2017.09 built on MoarVM version 2017.09.1
implementing Perl 6.c.

This may be related to https://rt.perl.org/Public/Bug/Display.html?id=132313

This appears to be not a bug but simply the goodness of floating point math. I get the same result in C​:

  #include <stdio.h>
  int main(void) {
  puts( 777777777777777777777.0L/1000000000000000000000.0L
  > 7777777777777777777771.0L/10000000000000000000000.0L
  ? "More" : "Less or Same");
  return 0;
  }

  // OUTPUT​: More

@p6rt
Copy link
Author

p6rt commented Oct 21, 2017

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

@p6rt
Copy link
Author

p6rt commented Oct 21, 2017

From @jkeenan

Should the last word in the Subject be 'monotonic' rather than 'monotonous'?

--
James E Keenan (jkeenan@​cpan.org)

@p6rt
Copy link
Author

p6rt commented Apr 13, 2018

From @zoffixznet

On Fri, 20 Oct 2017 07​:34​:04 -0700, victor.adam@​derpymail.org wrote​:

How to reproduce
----------------

perl6 -e 'my ($a, $b) = (0.777777777777777777777,
0.7777777777777777777771); say $a <=> $b, " ", Num($a) <=> Num($b)'

Expected behavior
-----------------

Prints `Less Less`, or `Less Same`, depending on how rounding is done.

Actual behavior
---------------

Prints `Less More`. This seems inconsistent​: $a is strictly smaller
than $b, yet Num($a) is strictly larger than Num($b).

Version information
-------------------

This is Rakudo version 2017.09 built on MoarVM version 2017.09.1
implementing Perl 6.c.

This may be related to https://rt.perl.org/Public/Bug/Display.html?id=132313

Thank you for the report. This is now fixed (specifically, the Num version now gives "Same" as
there's not enough precision available to represent those Rats as different numbers)

Fix​: rakudo/rakudo@a760ac3cfc6426d9bd2fb00db
  MoarVM/MoarVM@b735866ddee9bd719440e5c82
Test​: Raku/roast@db0c58b5f763b085e

On Fri, 20 Oct 2017 17​:44​:40 -0700, cpan@​zoffix.com wrote​:

This appears to be not a bug but simply the goodness of floating point
math. I get the same result in C​:

You're wrong, 2017-Zoffix. The result you got in C is because you incorrectly used doubles to do the division.

@p6rt
Copy link
Author

p6rt commented Apr 13, 2018

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

@p6rt p6rt closed this as completed Apr 13, 2018
@p6rt p6rt added the math label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant