How to compute the smallest integer number strictly greater than a given number?


#1

Is there a Julia function that returns the smallest integer number strictly greater than a given number? For example, if I give 0.5, it returns me 1.0. If I give 1.0, it returns 2.0? ceil() can do the former example for sure, but for the latter example, it just returns me 1.0.

By integer, I mean the Float64 representation of an integer, not any Int type. Thanks!


#2

floor + 1?

julia> blah(x) = floor(x) + 1
blah (generic function with 1 method)
julia> blah(0.5)
1.0
julia> blah(1.0)
2.0
julia> blah(0.9)
1.0
julia> blah(-.5)
0.0
julia> blah(-1.0)
0.0

#3

Brilliant!! Thanks!!


#5

Not sure if it matters for your use case, but f(x) = floor(Int, x) + 1 would be a bit more robust, as not all integers can be represented as floating point

julia> f(x) = floor(Int, x) + 1
f (generic function with 1 method)

julia> g(x) = floor(x) + 1
g (generic function with 1 method)

julia> 2^53
9007199254740992

julia> f(float(2^53))
9007199254740993

julia> Int(g(float(2^53)))
9007199254740992