Permalink
Browse files

flipsign implementation for Float32 and Float64.

  • Loading branch information...
1 parent 840c1fb commit 20b9453791901ec64b73b6b1d519e6a89168056e @StefanKarpinski StefanKarpinski committed Jan 30, 2014
Showing with 6 additions and 0 deletions.
  1. +6 −0 base/floatfuncs.jl
View
@@ -6,6 +6,12 @@ copysign(x::Float32, y::Real) = copysign(x, float32(y))
copysign(x::Float64, y::Real) = copysign(x, float64(y))
@vectorize_2arg Real copysign
+flipsign(x::Float64, y::Float64) = box(Float64,xor_int(unbox(Float64,x),and_int(unbox(Float64,y),0x8000000000000000)))
+flipsign(x::Float32, y::Float32) = box(Float32,xor_int(unbox(Float32,x),and_int(unbox(Float32,y),0x80000000)))
+flipsign(x::Float32, y::Real) = flipsign(x, float32(y))
+flipsign(x::Float64, y::Real) = flipsign(x, float64(y))
+@vectorize_2arg Real flipsign
+
signbit(x::Float64) = signbit(reinterpret(Int64,x))
signbit(x::Float32) = signbit(reinterpret(Int32,x))
signbit(x::Float16) = signbit(reinterpret(Int16,x))

0 comments on commit 20b9453

Please sign in to comment.