**To**:**oar.pmel.ferret_users@xxxxxxxx****Subject**:**Re: [ferret_users] ceil, floor, and round****From**:**Andrew Wittenberg <Andrew.Wittenberg@xxxxxxxx>**- Date: Wed, 30 Sep 2009 12:44:27 -0400 (EDT)
- In-reply-to: <20090929.155434.208916082.furue@xxxxxxxxxx>
- References: <web-8791555@xxxxxxxxxxxxxxxxxxxxxx> <bbc45a60c42aee6ad3e72feb937742e9.squirrel@xxxxxxxxxxxxxxxxxxxxxxxxxxx> <20090929.155434.208916082.furue@xxxxxxxxxx>
- Reply-to: Andrew Wittenberg <Andrew.Wittenberg@xxxxxxxx>
- Sender: owner-ferret_users@xxxxxxxx

let floor_a = int(a) - (a LT 0 AND int(a) NE a) let ceil_a = int(a) + (a GT 0 AND int(a) NE a) let round_a = int(a-.5+(a GE 0)) Andrew On Tue, 29 Sep 2009, Ryo Furue wrote:

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:*Ryo Furue

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

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

**Re: [ferret_users] ceil, floor, and round***From:*Ryo Furue

- Previous by thread:
**Re: [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