Why does this complex rationality give an overflow error in Julia?

When I want Julia (0.4.3) to calculate (2.4 - 1.2im) // (0.7 - 0.6im), it gives an overflow error:

ERROR: OverflowError()
 in * at rational.jl:188
 in // at rational.jl:45
 in // at rational.jl:42

However (24 - 12 im) // (0.7 - 0.6im), mathematically essentially the same thing works. It also (2.4 - 1.2im) / (0.7 - 0.6im)works, but it doesn’t give a rational, of course.

Is this a mistake, or am I doing something wrong? Are there rational solutions that Julia cannot work with?

+3
source share
1 answer

You should use:

(24//10 - 12im//10) / (7//10 - 6im//10)

instead.

? , , - 0.7 2.4, . , Rational:

julia> Rational{Int64}(0.7)
3152519739159347//4503599627370496

//, , , , , .

OverflowError? Rational{Int64}, , Int64. , , , :

julia> Rational{Int64}(0.7) * Rational{Int64}(0.7)
ERROR: OverflowError()
 in *(::Rational{Int64}, ::Rational{Int64}) at ./rational.jl:196
 in eval(::Module, ::Any) at ./boot.jl:234
 in macro expansion at ./REPL.jl:92 [inlined]
 in (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:46

OverflowError , , . , Rational ! Rational{BigInt}, , , .

, , 0.7 0.7. , , 0.7 0.6999999999999999555910790149937383830547332763671875. 7//10 .

+4

Source: https://habr.com/ru/post/1648158/


All Articles