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

Implement floating-point manipulation functions for BigFloat #11007

Merged

Conversation

HertzDevil
Copy link
Contributor

BigFloat already has an implementation of frexp because hash needs it (I think); this PR adds the remaining floating-point manipulation operations.

Methods that take an additional integer accept an Int directly, so this takes care of the allowed conversions in #10907.

BigFloat from GMP doesn't have the notion of signed zeros, so copysign is only an approximation. (As usual, MPFR floats feature signed zeros.)

@straight-shoota
Copy link
Member

CI is failing on Windows: https://github.com/crystal-lang/crystal/actions/runs/10698882947/job/29660333970?pr=11007

  1) BigFloat Math .frexp
     Failure/Error: Math.frexp(2.to_big_f ** 1_000_000_000_000).should eq({0.5, 1_000_000_000_001})

       Expected: {0.5, 1000000000001}
            got: {2.43829426113685079336e+327749382, -727379967}

     # spec\std\big\big_float_spec.cr:585

  2) BigFloat Math .logb
     Failure/Error: Math.ilogb(2.to_big_f ** 1_000_000_000_000).should eq(1_000_000_000_000.to_big_f)

       Expected: 1000000000000.0
            got: -727379968

     # spec\std\big\big_float_spec.cr:559

  3) BigFloat Math .ilogb
     Failure/Error: Math.ilogb(2.to_big_f ** 1_000_000_000_000).should eq(1_000_000_000_000)

       Expected: 1000000000000
            got: -727379968

     # spec\std\big\big_float_spec.cr:553

@HertzDevil HertzDevil marked this pull request as draft September 5, 2024 10:12
@HertzDevil
Copy link
Contributor Author

HertzDevil commented Sep 5, 2024

These exponents will overflow even when GMP / MPIR handles the internal exponents correctly, so a fix similar to #14971 is needed. Moreover all BigFloats are always less than 2 ** 0x1f_ffffffc0 when LibGMP::MpExp is 32-bit and LibGMP::MpLimb is 64-bit, anything above that will lead to an overflow in the internal exponent

@HertzDevil HertzDevil marked this pull request as ready for review September 5, 2024 13:46
@straight-shoota straight-shoota added this to the 1.14.0 milestone Sep 7, 2024
@straight-shoota straight-shoota merged commit fdbaeb4 into crystal-lang:master Sep 10, 2024
63 of 65 checks passed
@HertzDevil HertzDevil deleted the feature/bigfloat-manip branch September 12, 2024 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants