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
std.bigint.BigInt: allow casting to floating point numbers #7151
Conversation
Thanks for your pull request, @n8sh! Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + phobos#7151" |
d99bde8
to
687a993
Compare
Is |
@Biotronic: let's use that to make |
c4f985c
to
7067d48
Compare
Added path for arbitrarily high precision floating point numbers. Locally tested that it works for 80 bit reals. |
9df8cdc
to
26cd036
Compare
I may have to rethink the rounding used in |
98f5d9b
to
453575c
Compare
I've changed |
9f28551
to
e27af58
Compare
e27af58
to
f31a00e
Compare
f1e4a0e
to
221ce25
Compare
std/bigint.d
Outdated
// If we wanted to round ties away from 0 we could just add | ||
// roundUpInc to sansExponent. The more complicated logic is | ||
// so ties are rounded to even, which matches the default | ||
// rounding behavior when casting int/long to float/double. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this seemingly isn't the default rounding mode on the Win32 & FreeBSD_32 test machines, my inclination is to abandon this rounding mode and round ties away from zero for float/double.
0ea7738
to
631f03d
Compare
…oating point types
631f03d
to
374cbd3
Compare
Is this still WIP? |
@berni44 the WIP tag is because the rounding behavior might astonish someone who used it without reading the documentation.
Any way of handling rounding had disadvantages. I'm not convinced that this choice is the best. |
Also, this isn't great:
|
I had exactly the same problems with the functions that print floating point numbers in std.format. But there is a slight difference: Printing is IMHO mainly done for humans and there is IMHO "ties away from zero" the expected choice. Here, the numbers might be used to do some more calculating and as far as I know "ties to even" works better for that, because it can straighten out the accumulating errors. What I currently do in std.format is to read out the rounding mode of the processor and use this mode (round down, round up, round to zero, round to nearest with ties to even). That's what printf does and the reason why printing floats isn't pure. |
Limitation:
casting to & comparison with quadruple precision floating point numbers are not supported.The path for 80 bit (EDIT: and greater) extended floats use std.math.scalbn which currently is impureand non-CTFE-able.