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

BigFloat, BigInt comparison is intransitive #3399

Closed
StefanKarpinski opened this issue Jun 14, 2013 · 9 comments
Closed

BigFloat, BigInt comparison is intransitive #3399

StefanKarpinski opened this issue Jun 14, 2013 · 9 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@StefanKarpinski
Copy link
Member

julia> i1 = BigInt(10)^1000;

julia> i2 = BigInt("10000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");

julia> i1 == i2
false

julia> i1 == BigFloat(10)^1000
true

julia> i2 == BigFloat(10)^1000
true

Discussion:

https://groups.google.com/forum/?fromgroups#!searchin/julia-dev/rational/julia-dev/2JcZdFKisis/Ag9rBJrrqQQJ

@quinnj
Copy link
Member

quinnj commented Jun 4, 2014

Behavior probably changed with the hashing updates. Good to close?

In  [76]: i1 == i2

Out [76]: false

In  [77]:  i1 == BigFloat(10)^1000

Out [77]: false

In  [78]: i2 == BigFloat(10)^1000

Out [78]: false

@JeffBezanson
Copy link
Member

That's really strange; I still get

julia> i1 == i2
false

julia> i1 == BigFloat(10)^1000
true

julia> i2 == BigFloat(10)^1000
true

@quinnj
Copy link
Member

quinnj commented Jun 4, 2014

That's fishy. Is there a windows issue somewhere in here?

@quinnj
Copy link
Member

quinnj commented Jun 4, 2014

What are the following for mac/linux?

In  [13]: a,b = promote(i2,BigFloat(10)^1000)

Out [13]: (1.000000000000000000000000000000000000000000000000000000000000000000000000000004e+1000 with 256 bits of precision,9.99999999999999999999999999999999999999999999999999999999999999999999999999968e+999 with 256 bits of precision)

In  [14]: (a.prec,b.prec)

Out [14]: (256,256)

In  [15]: a.sign,b.sign

Out [15]: (1,1)

In  [16]: a.exp,b.exp

Out [16]: (3322,3322)

In  [17]: a.d,b.d

Out [17]: (Ptr{Uint32} @0x0000000014c29ef8,Ptr{Uint32} @0x0000000014c29ec8)

@JeffBezanson
Copy link
Member

Aha; I get

julia> a,b = promote(i2,BigFloat(10)^1000)
(1.000000000000000000000000000000000000000000000000000000000000000000000000000004e+1000 with 256 bits of precision,1.000000000000000000000000000000000000000000000000000000000000000000000000000004e+1000 with 256 bits of precision)

Looks like different rounding.

@quinnj
Copy link
Member

quinnj commented Jun 11, 2014

Hmmm.......I'm seeing a test failure that I believe is related to this:
The test is test/mpfr.jl, lines 771-778

i1 = BigInt(10)^1000
i2 = BigInt("10000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
f = BigFloat(10)^1000
@test i1 != i2
@test i1 != f
@test i2 != f

@test f > i1

But I'm seeing:

julia> i1 = BigInt(10)^1000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000

julia> f = BigFloat(10)^1000
9.99999999999999999999999999999999999999999999999999999999999999999999999999968e
+999 with 256 bits of precision

julia> f > i1
false

@andrioni
Copy link
Member

That's pretty weird, since not even rounding down BigFloat(10)^1000 I can reproduce your issue on OS X, since the answer you get is even smaller:

julia> f = BigFloat("9.99999999999999999999999999999999999999999999999999999999999999999999999999968e+999")
9.99999999999999999999999999999999999999999999999999999999999999999999999999968e+999 with 256 bits of precision

julia> g = with_rounding(BigFloat, RoundDown) do
         BigFloat(10)^1000
       end
9.999999999999999999999999999999999999999999999999999999999999999999999999999953e+999 with 256 bits of precision

julia> g > f
true

@Keno
Copy link
Member

Keno commented Jun 12, 2014

Could this be an mpfr problem. I notice the mpfr structures are significantly smaller on windows due to the whole ILP64 vs LLP64 thing.

@tkelman
Copy link
Contributor

tkelman commented Jun 20, 2014

Found a simple fix for this Win64 test failure, PR incoming. BigFloat^Int goes to MPFR on every platform other than Win64, because Win64 is the only place that Julia Int is bigger than Clong. On Win64 it's going to power_by_squaring resulting in a differently-rounded result.

tkelman added a commit to tkelman/julia that referenced this issue Jun 20, 2014
Ref JuliaLang#3399

BigFloat^Int goes to MPFR on every platform other than Win64,
because Win64 is the only place that Julia Int is bigger than Clong.
On Win64 it's going to power_by_squaring resulting in a differently-rounded result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

6 participants