Skip to content

Commit

Permalink
Introduce ifloor and iceil functions [closes #234].
Browse files Browse the repository at this point in the history
Also:
  - add a number of vectorized functions on darrays
  - shorten a couple of functions in versions.j
  • Loading branch information
StefanKarpinski committed Oct 24, 2011
1 parent 5713db9 commit abc7546
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 33 deletions.
11 changes: 7 additions & 4 deletions j/darray.j
Original file line number Diff line number Diff line change
Expand Up @@ -750,10 +750,13 @@ function map_vectorized(f, A::SubOrDArray)
T, size(A), distdim(A), procmap(A))
end

for f = (:ceil, :floor, :trunc, :round, :iround, :itrunc,
:sqrt, :cbrt, :sin, :cos, :tan, :sinh, :cosh, :tanh,
:asin, :acos, :atan,
:log, :log2, :exp, :expm1)
for f = (:ceil, :floor, :trunc, :round,
:iceil, :ifloor, :itrunc, :iround,
:sqrt, :cbrt, :log, :log2, :exp, :expm1,
:sin, :cos, :tan, :cot, :sec, :csc,
:sinh, :cosh, :tanh, :coth, :sech, :csch,
:asin, :acos, :atan, :acot, :asec, :acsc,
:acoth, :asech, :acsch, :sinc, :cosc, :atan2)
@eval ($f)(A::SubOrDArray) = map_vectorized($f, A)

This comment has been minimized.

Copy link
@JeffBezanson

JeffBezanson Oct 25, 2011

Member

i'm tempted to offer you a nickel for every time somebody needs to compute the asech of a darray :)

This comment has been minimized.

Copy link
@StefanKarpinski

StefanKarpinski Oct 25, 2011

Author Member

True. But in principle, it should still work, no?

This comment has been minimized.

Copy link
@JeffBezanson

JeffBezanson Oct 25, 2011

Member

Sure. But sec, for example, is defined as 1./cos, so it would work, just a bit less efficiently. I'd almost prefer that just for the sake of code density. And atan2 won't work here because it takes 2 arguments :)

end

Expand Down
22 changes: 15 additions & 7 deletions j/float.j
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
## floating point conversions ##

iround(x::Float32) = boxsi32(fpiround32(unbox32(x)))
iround(x::Float64) = boxsi64(fpiround64(unbox64(x)))

itrunc(x::Float32) = boxsi32(fptosi32(unbox32(x)))
itrunc(x::Float64) = boxsi64(fptosi64(unbox64(x)))
## conversions to floating-point ##

convert(::Type{Float32}, x::Bool) = boxf32(sitofp32(unbox8(x)))
convert(::Type{Float32}, x::Int8) = boxf32(sitofp32(unbox8(x)))
Expand Down Expand Up @@ -45,6 +39,20 @@ float32(x) = convert(Float32, x)
float64(x) = convert(Float64, x)
float(x) = convert(Float, x)

## conversions from floating-point ##

iround(x::Float32) = boxsi32(fpiround32(unbox32(x)))
iround(x::Float64) = boxsi64(fpiround64(unbox64(x)))
itrunc(x::Float32) = boxsi32(fptosi32(unbox32(x)))
itrunc(x::Float64) = boxsi64(fptosi64(unbox64(x)))

iceil(x::Float) = int(ceil(x)) # TODO: fast primitive for iceil
ifloor(x::Float) = int(floor(x)) # TOOD: fast primitive for ifloor

convert(::Type{Int}, x::Float) = iround(x)
convert(::Type{Int32}, x::Float) = float32(iround(x))
convert(::Type{Int64}, x::Float) = float64(iround(x))

This comment has been minimized.

Copy link
@JeffBezanson

JeffBezanson Oct 25, 2011

Member

what??

This comment has been minimized.

Copy link
@StefanKarpinski

StefanKarpinski Oct 25, 2011

Author Member

Uh, yeah. Sorry, that's obviously wrong.


## floating point promotions ##

promote_rule(::Type{Float64}, ::Type{Float32} ) = Float64
Expand Down
2 changes: 2 additions & 0 deletions j/floatfuncs.j
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ end

@vectorize_1arg Real iround
@vectorize_1arg Real itrunc
@vectorize_1arg Real ifloor
@vectorize_1arg Real iceil
@vectorize_1arg Number abs
12 changes: 8 additions & 4 deletions j/int.j
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,15 @@ signed(x::Uint16) = convert(Int16, x)
signed(x::Uint32) = convert(Int32, x)
signed(x::Uint64) = convert(Int64, x)

round(x::Int) = x
round(x::Int) = x
trunc(x::Int) = x
floor(x::Int) = x
ceil(x::Int) = x

iround(x::Int) = x
trunc(x::Int) = x
floor(x::Int) = x
ceil(x::Int) = x
itrunc(x::Int) = x
ifloor(x::Int) = x
iceil(x::Int) = x

## integer promotions ##

Expand Down
21 changes: 3 additions & 18 deletions j/version.j
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,9 @@ $(jl)|__/$(tx) |

\033[0m"

function color_available()
if run(`tput setaf 0`)
return true
end
if has(ENV, "TERM")
term = ENV["TERM"]
return term=="xterm" || term=="xterm-color"
end
false
end
color_available() =
run(`tput setaf 0`) || has(ENV, "TERM") && matches(r"^xterm", ENV["TERM"])

function banner()
if color_available()
print(jl_banner_color)
else
print(jl_banner_plain)
end
end
banner() = print(color_available() ? jl_banner_color : jl_banner_plain)

end # begin

0 comments on commit abc7546

Please sign in to comment.