Re: floor()
- Posted by jluethje at gmx.de
Apr 22, 2002
Hi,
Ricardo wrote:
> Well, not exactly adding 1, because if the argument is integer (after
> the division) you'll get a result off by 1.
Absolutely right. A good description can be found e.g. at
http://mathworld.wolfram.com/FloorFunction.html
and related pages.
> These issues are treated in my package General Functions, where one
> can find FloorTowardsZero
This is called "fix" in many BASIC dialects and -- most intuitive for
me -- "trunc" e.g. in PASCAL or SPSS.
The principle of trunc(x) is:
if x < 0 then
return ceil(x)
else
return floor(x)
end if
> Ceil, etc. routines. For example, Ceil(a) is -floor(-a).
Because those are standard functions (which are implemented in many
languages), I would appreciate it if
ceil(x)
trunc(x)
frac(x) --> e.g. frac(-2.7) = -0.7
abs(x)
sign(x)
would be part of the official Euphoria release.
Regards,
Juergen
-----------------
>> [...]
>> So be aware, when doing arithmetics on the results to add 1 to the
>> floor(-x/y) result.
>> [...]
|
Not Categorized, Please Help
|
|