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

Unify Rat and FatRat stringification. Fixes some TODO tests. #1840

Closed
wants to merge 2 commits into from
Closed

Unify Rat and FatRat stringification. Fixes some TODO tests. #1840

wants to merge 2 commits into from

Conversation

thundergnat
Copy link
Contributor

Remove some branching logic and use same parameters for all
Rationals. Should be same or microscopically faster for small
denominator Rats/FatRats and probably a few percent slower for
some large denominator Rats. Rats no longer truncate fractional
portions that can be exactly expressed.

Remove some branching logic and uses same parameters for all
Rationals. Should be same or microscopically faster for small
denominator Rats/FatRats and probably a few percent slower for
some large denominator Rats. Rats no longer truncate fractional
portions that can be exactly expressed.
$precision = nqp::chars($!denominator.Str) + nqp::chars($whole.Str) + 1;
$fract *= nqp::pow_I(10, nqp::decont($precision), Num, Int);
}
$precision = nqp::chars(~$!denominator) + nqp::chars(~$whole) +< 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reasoning for multiplication of the whole part by 2? Not following how the length of the whole part fits in into the equation of calculating precision even in the original code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And that means (1000*2⁶²)/(2⁶²+1) has 19 chars after the decimal, yet (10²⁰⁰*2⁶²)/(2⁶²+1) has 418 chars after the decimal (and is now 5.5x slower to generate). I'm not following at all the logic of this precision difference. The reverse would be more understandable, but not the behaviour of generating extra precision for numbers large enough for it to matter less.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more I think about this pull request, the less I think it is a good idea. The obvious deficiencies that Zoffix++ pointed out are a huge red flag. I've spent some time trying to come up with a better heuristic for determining a "correct" number of decimal places to return but they have all been wildly inaccurate or despairingly slow.

At this point I think it might be better to drop this for CORE. Extremely precise Rat/FatRat strings may be a niche better filed by a module.

@thundergnat
Copy link
Contributor Author

Closing this request. Obvious (in retrospect) deficiencies pointed out by Zoffix++. Probably better implementing in a module first if it can be improved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants