Julia: Float rounding issue

Created on 8 May 2020  路  2Comments  路  Source: JuliaLang/julia

The expression

(2/6)^5 == 2^5 / 6^5

is false? This language is intended to be good at Math. Ruby and Python both evaluated it to true.

version 1.4.1

Most helpful comment

Use rationals:

julia> (2//6)^5 == 2^5 // 6^5
true

All 2 comments

Standard floating-point behavior. Python3:

>>> (2/6)**5
0.004115226337448558
>>> 2**5 / 6**5
0.00411522633744856
>>>

Julia:

julia> (2/6)^5
0.004115226337448558

julia> 2^5 / 6^5
0.00411522633744856

In Python2 and Ruby they're equal because both sides are zero since / does integer division.

Use rationals:

julia> (2//6)^5 == 2^5 // 6^5
true
Was this page helpful?
0 / 5 - 0 ratings

Related issues

felixrehren picture felixrehren  路  3Comments

tkoolen picture tkoolen  路  3Comments

m-j-w picture m-j-w  路  3Comments

omus picture omus  路  3Comments

TotalVerb picture TotalVerb  路  3Comments