我对Julia - Windows上的1.0.0版本非常陌生。documentation声明了以下内容
julia> Inf / Inf
NaN但是当我执行以下操作时,我得到了不同的结果
julia> 1/0
Inf
julia> 1/0 / 1/0 # this should be NaN right, tried (1/0)/(1/0) as well
Inf
julia> 1/0
Inf
julia> ans/ans
NaN为什么1/0 / 1/0不是NaN,而ans/ans是呢?
发布于 2018-09-07 17:43:30
你实际上有:
julia> (1/0)/(1/0)
NaN所以这是一致的。
现在关于:
julia> 1/0 / 1/0
Inf请观察它是如何评估的:
julia> :(1/0 / 1/0)
:(((1 / 0) / 1) / 0)因此,我们得到一个从左到右的标准评估(正如预期的那样)。然后你会得到:
julia> 1/0
Inf
julia> (1/0)/1
Inf
julia> ((1/0)/1)/0
Inf一切都很好。
实际上,这里你有一个特殊的东西要注意(这与你的问题没有直接关系,但很高兴知道,因为它可能会出现在下一个问题中):
julia> Inf / 0
Inf
julia> Inf / (-0)
Inf
julia> Inf / (0.0)
Inf
julia> Inf / (-0.0)
-Inf原因是整数0与-0相同
julia> 0 === -0
true但是浮点数携带符号位:
julia> 0.0 === -0.0
falsehttps://stackoverflow.com/questions/52218890
复制相似问题