Skip to content

Commit

Permalink
Drop libm sqrt, sin, cos in favor of LLVM's versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Jan 30, 2011
1 parent ad8f8fd commit 6c2caec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
4 changes: 4 additions & 0 deletions floatfuncs.j
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ cos(x::Float32) = boxf32(cos_float(unbox32(x)))
^(x::Float64, p::Int32) = boxf64(powi_float(unbox64(x),unbox32(p)))
^(x::Float32, p::Int32) = boxf32(powi_float(unbox32(x),unbox32(p)))

sqrt(x::Real) = sqrt(float(x))
sin(x::Real) = sin(float(x))
cos(x::Real) = cos(float(x))

num2hex(x::Float32) = uint2str(boxui32(unbox32(x)),16,16)
num2hex(x::Float64) = uint2str(boxui64(unbox64(x)),16,16)

Expand Down
34 changes: 15 additions & 19 deletions math_libm.j
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ macro vectorize(f)
end
end

for f = {:sin, :cos, :tan, :sinh, :cosh, :tanh, :asin, :acos, :atan, :log,
:log2, :log10, :log1p, :logb, :exp, :exp2, :expm1, :erf, :erfc,
:sqrt, :cbrt, :ceil, :floor, :nearbyint, :round, :rint, :trunc}
for f = {:tan, :sinh, :cosh, :tanh, :asin, :acos, :atan, :log, :log2,
:log10, :log1p, :logb, :exp, :exp2, :expm1, :erf, :erfc,
:cbrt, :ceil, :floor, :nearbyint, :round, :rint, :trunc}
@eval begin
($f)(x::Float64) = ccall(dlsym(libm,$string(f)), Float64, (Float64,), x)
($f)(x::Float32) = ccall(dlsym(libm,$strcat(string(f),"f")), Float32, (Float32,), x)
($f)(x::Real) = ($f)(convert(Float64,x))
($f)(x::Real) = ($f)(float(x))
@vectorize $f
end
end
Expand All @@ -29,28 +29,24 @@ for f = {:lrint, :lround, :ilogb}
end
end

abs(x::Float64) = ccall(dlsym(libm, :fabs), Float64, (Float64,), x)
abs(x::Float64) = ccall(dlsym(libm, :fabs), Float64, (Float64,), x)
abs(x::Float32) = ccall(dlsym(libm, :fabsf), Float32, (Float32,), x)
@vectorize abs

for f = {:atan2, :pow, :fmod, :copysign, :hypot, :fmin, :fmax, :fdim}
@eval begin
($f)(x::Float64, y::Float64) = ccall(dlsym(libm,$string(f)),
Float64,
(Float64, Float64,),
x, y)
($f)(x::Float32, y::Float32) = ccall(dlsym(libm,$strcat(string(f),"f")),
Float32,
(Float32, Float32),
x, y)
($f)(x::Real, y::Real) = ($f)(convert(Float64,x),convert(Float64,y))
($f)(x::Float64, y::Float64) =
ccall(dlsym(libm,$string(f)), Float64, (Float64, Float64,), x, y)
($f)(x::Float32, y::Float32) =
ccall(dlsym(libm,$strcat(string(f),"f")), Float32, (Float32, Float32), x, y)
($f)(x::Real, y::Real) = ($f)(float(x),float(y))
end
end

ldexp(x::Float64,e::Int32) = ccall(dlsym(libm, :ldexp), Float64, (Float64,Int32), x, e)
ldexp(x::Float64,e::Int32) = ccall(dlsym(libm, :ldexp), Float64, (Float64,Int32), x, e)
ldexp(x::Float32,e::Int32) = ccall(dlsym(libm, :ldexpf), Float32, (Float32,Int32), x, e)

rand() = ccall(:rand_double, Float64, ())
randf() = ccall(:rand_float, Float32, ())
randui32() = ccall(:genrand_int32, Uint32, ())
randn() = ccall(:randn, Float64, ())
rand() = ccall(:rand_double, Float64, ())
randf() = ccall(:rand_float, Float32, ())
randui32() = ccall(:genrand_int32, Uint32, ())
randn() = ccall(:randn, Float64, ())

0 comments on commit 6c2caec

Please sign in to comment.