Types 使用浮点输入时,在Julia中键入一般分布的稳定函数
在Julia中,我有这样一个函数:Types 使用浮点输入时,在Julia中键入一般分布的稳定函数,types,floating-point,julia,type-stability,Types,Floating Point,Julia,Type Stability,在Julia中,我有这样一个函数: function f(x::Float64, c::Float64) if x <= 0 return(0.0) elseif x <= c return(x / c) else return(1.0) end end 函数f(x::Float64,c::Float64) 如果x,one和zero函数在这里很有用: function f(x, c) if x
function f(x::Float64, c::Float64)
if x <= 0
return(0.0)
elseif x <= c
return(x / c)
else
return(1.0)
end
end
函数f(x::Float64,c::Float64)
如果x,
one
和zero
函数在这里很有用:
function f(x, c)
if x <= 0
return zero(x)
elseif x <= c
return x/c
else
return one(x)
end
end
函数f(x,c)
如果x 32位计算机确实支持浮动64,则可以。32/64位的区别仅适用于整数。@谢谢,这是有用的信息,
function f{T<:FloatingPoint}(x::T, c::T)
if x <= 0
return zero(T)
elseif x <= c
return x/c
else
return one(T)
end
end