diff --git a/floatfuncs.j b/floatfuncs.j index 8b5f5a6bd75a1..d9f5cf29c1292 100644 --- a/floatfuncs.j +++ b/floatfuncs.j @@ -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) diff --git a/math_libm.j b/math_libm.j index 25dffd46d9eef..b4bd9e04c1659 100644 --- a/math_libm.j +++ b/math_libm.j @@ -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 @@ -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, ())