首页 > 解决方案 > 如何在 Julia 中指定无理数的类型?

问题描述

这是一个惊喜:

$ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.1.1 (2019-05-16)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> typeof((Base.MathConstants).e)
Irrational{:ℯ}

julia> typeof((Base.MathConstants).e) == Irrational{:e}
false

如何Irrational{:e}在 Julia 1.1.1 中编写类型?

这个表达式在 Julia 0.5 中返回 true,但这仅仅是因为e它是一个顶级标识符。从 0.5 到现在,语言发生了一些变化。我发现它e已移至Base.MathConstants,但我还没有弄清楚如何编写它的类型。REPL 说了一件事,但它说的不能用在==表达式中。

标签: genericsjulia

解决方案



推荐阅读