Julia: Inconsistent π in Julia

Created on 30 Jun 2020  ·  2Comments  ·  Source: JuliaLang/julia

julia> versioninfo()
Julia Version 1.3.1
Commit 2d5741174c (2019-12-30 21:36 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-6900K CPU @ 3.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, broadwell)

julia> pi
π = 3.1415926535897...

julia> -pi
-3.141592653589793

julia> +pi
π = 3.1415926535897...

Q1) if pi is not truncated, why should -pi be truncated to to Float64?

Q2) If we have a good justification for the above question, why do we inconsistently truncate -pi to Float64, but do not truncate +pi?

Most helpful comment

Base julia contains no symbolic manipulation capabilities (though you can load various such packages). The mathematical constants of type Irrational are a bit of a hack and take on whatever the precision of the other operation in a binary operation is. Of course, for unary operations, there's nothing to indicate what the precision should be, so it defaults to Float64. The reason this doesn't happen with unary plus, is that unary plus is the identity so it preserves the irrational object itself. Lastly, it's usually better to ask questions on https://discourse.julialang.org/, since those are read by a larger audience of people and is a better forum for discussion. GitHub issues are best suited for tracking actionable changes (and any actionable outcome from a discourse discussion can always be reflected here :) ). Cheers!

All 2 comments

Base julia contains no symbolic manipulation capabilities (though you can load various such packages). The mathematical constants of type Irrational are a bit of a hack and take on whatever the precision of the other operation in a binary operation is. Of course, for unary operations, there's nothing to indicate what the precision should be, so it defaults to Float64. The reason this doesn't happen with unary plus, is that unary plus is the identity so it preserves the irrational object itself. Lastly, it's usually better to ask questions on https://discourse.julialang.org/, since those are read by a larger audience of people and is a better forum for discussion. GitHub issues are best suited for tracking actionable changes (and any actionable outcome from a discourse discussion can always be reflected here :) ). Cheers!

Thanks,
I thought that is indeed an issue to be fixed; sure, in future, will discuss such things in discourse.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

m-j-w picture m-j-w  ·  3Comments

StefanKarpinski picture StefanKarpinski  ·  3Comments

omus picture omus  ·  3Comments

StefanKarpinski picture StefanKarpinski  ·  3Comments

musm picture musm  ·  3Comments