**To**:**ferret_users@xxxxxxxx****Subject**:**Re: [ferret_users] ceil, floor, and round****From**:**Ryo Furue <furue@xxxxxxxxxx>**- Date: Tue, 29 Sep 2009 15:54:34 -1000 (HST)
- In-reply-to: <bbc45a60c42aee6ad3e72feb937742e9.squirrel@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- References: <web-8791555@xxxxxxxxxxxxxxxxxxxxxx> <bbc45a60c42aee6ad3e72feb937742e9.squirrel@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Sender: owner-ferret_users@xxxxxxxx

Hi Peng, | Does ferret have functions similar to ceil, floor, round in matlab (please | see their definitions below)? I don't know the official answer, but I guess Ferret doesn't have those functions built in. In case it doesn't, I give some ideas on how to define them. | CEIL(X) rounds the elements of X to the nearest integers towards infinity. | FLOOR(X) rounds the elements of X to the nearest integers towards minus | infinity. | ROUND(X) rounds the elements of X to the nearest integers. You can construct them from the "int()" function, which Ferret does have. INT is the same as FLOOR for positive arguments but it truncates toward zero instead of toward minus infinity: INT(1.4) == 1 INT(-1.4) == -1 So, FLOOR(a) = if (a is a whole number) then a else if (a < 0) then INT(a) - 1 else INT(a) In Ferret statements, let int_a = int(a) let floor_a = if int_a eq a then a else floor_a_helper let floor_a_helper = if a lt 0 then int_a - 1 else int_a Likewise, ROUND(a) = if (a is a whole number) then a else if (a < 0) then INT(a - 0.5) else INT(a + 0.5) These formulae are rather tedious. There may be better definitions. Regards, Ryo

**Follow-Ups**:**Re: [ferret_users] ceil, floor, and round***From:*Andrew Wittenberg

**References**:**[ferret_users] ceil, floor, and round***From:*Ge Peng

- Previous by thread:
**[ferret_users] ceil, floor, and round** - Next by thread:
**Re: [ferret_users] ceil, floor, and round**

Contact Us

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Privacy Policy | Disclaimer | Accessibility Statement