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

<1/3>.base(10, *) hangs/timeout #1872

Open
lucasbuchala opened this issue May 26, 2018 · 9 comments

Comments

Projects
None yet
4 participants
@lucasbuchala
Copy link
Collaborator

commented May 26, 2018

> say <1/2>.base(10, 5)
0.50000

> say <1/3>.base(10, 5)
0.33333

> say <1/2>.base(10, *)
0.5

> say <1/3>.base(10, *)
(Program hangs)

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

@zoffixznet

This comment has been minimized.

Copy link
Contributor

commented May 26, 2018

This seems to be as-documented:

For Rationals, the Whatever indicates that you wish all of the possible digits of the fractional part, but use caution: since there's no detection of repeating fractional parts (the algorithm will eventually stop after generating 2**63 digits).

Fixing this is blocked by the Halting Problem, isn't it?

@colomon

This comment has been minimized.

Copy link
Contributor

commented May 26, 2018

@zoffixznet

This comment has been minimized.

Copy link
Contributor

commented May 26, 2018

Ah right. Some googlefoo for possible solutions: https://softwareengineering.stackexchange.com/a/192077

@AlexDaniel

This comment has been minimized.

Copy link
Member

commented May 26, 2018

But what's the expected behavior? (assuming we can detect this)

@zoffixznet

This comment has been minimized.

Copy link
Contributor

commented May 26, 2018

But what's the expected behavior? (assuming we can detect this)

How about full non-repeating decimal + 1 instance of repeating portion? We probably have the algo in .base-repeating already, no?

$ perl6 -e 'use MONKEY; augment class Rat { method non-hang-base (\b, \p) { 
    self.base: b, p unless p.WHAT =:= Whatever; 
    self.base-repeating(b).join.Numeric } 
};  say .non-hang-base: 10, * for ½, ⅓, <1/19>'
0.5
0.3
0.052631578947368421
@zoffixznet

This comment has been minimized.

Copy link
Contributor

commented May 26, 2018

1 instance of repeating portion?

Hm, maybe something a bit smarter than that, since ⅓ -> 0.3 loses quite a bit of precision.

@colomon

This comment has been minimized.

Copy link
Contributor

commented May 26, 2018

@AlexDaniel

This comment has been minimized.

Copy link
Member

commented May 26, 2018

Eh, you can do something like 5.81̅4̅4̅ but that doesn't really help.

@zoffixznet

This comment has been minimized.

Copy link
Contributor

commented May 26, 2018

I'd expect the resultant string to be numifiable and the numification to be "close-enough" to the original number.

<Zoffix_> m: say +"5.81̅4̅4̅"
<camelia> rakudo-moar 01a373649: OUTPUT: «Cannot convert string to number: trailing characters after number in '5.8⏏1̅4̅4̅' (indicated by ⏏)␤  in block <unit> at <tmp> line 1␤␤»
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.