I am writing down a set of functions, and I want to make sure that some of the arguments are bounded within some given values.
For the sake of simplicity, say that I only have the following function:
function my_fun(w::Float64) ... end
w is bounded between
1.0. Right now, I am throwing an error if
w is lower than
0.0 or larger than
if w < 0 || w > 1 error("0 ≤ w ≤ 1"); end
I was wondering whether there are more efficient ways to approach this problem. I was thinking that since
w is a restricted
Float64 I could define a type that takes into account its bounds. However, I am not sure whether this is good practise, and if it can be easily done in Julia.
What would you recommend to do? In my application, I have many arguments to check and individual
if-end are not very tidy.