Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Sep 6, 2024
1 parent af7046d commit f0167f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions spec/std/big/big_float_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,12 @@ describe "BigFloat" do
it { assert_prints Float64::MAX.to_big_f.to_s, "1.79769313486231570815e+308" }
it { assert_prints Float64::MIN_POSITIVE.to_big_f.to_s, "2.22507385850720138309e-308" }

# least power of two with a base-10 exponent greater than Int32::MAX
(2.to_big_f ** 7133786264).to_s.should end_with("e+2147483648")
# least power of two with a base-10 exponent less than Int32::MIN
(2.to_big_f ** -7133786264).to_s.should end_with("e-2147483649")
it { (2.to_big_f ** 7133786264).to_s.should end_with("e+2147483648") } # least power of two with a base-10 exponent greater than Int32::MAX
it { (2.to_big_f ** -7133786264).to_s.should end_with("e-2147483649") } # least power of two with a base-10 exponent less than Int32::MIN
it { (10.to_big_f ** 3000000000 * 1.5).to_s.should end_with("e+3000000000") }
it { (10.to_big_f ** -3000000000 * 1.5).to_s.should end_with("e-3000000000") }
it { (10.to_big_f ** 10000000000 * 1.5).to_s.should end_with("e+10000000000") }
it { (10.to_big_f ** -10000000000 * 1.5).to_s.should end_with("e-10000000000") }
end

describe "#inspect" do
Expand Down
2 changes: 1 addition & 1 deletion src/big/big_float.cr
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ struct BigFloat < Float
# This value will be very close to an integer, which we then obtain with
# `#round`.
overflow_n = ((@mpf.@_mp_exp * Math.log10(256.0 ** sizeof(LibGMP::MpLimb)) - exponent10) / 256.0 ** sizeof(LibGMP::MpExp))
exponent10.to_i64 + overflow_n.to_i64 * (256_i64 ** sizeof(LibGMP::MpExp))
exponent10.to_i64 + overflow_n.round.to_i64 * (256_i64 ** sizeof(LibGMP::MpExp))
{% end %}
end

Expand Down

0 comments on commit f0167f1

Please sign in to comment.