**To**:**oar.pmel.ferret_users@xxxxxxxx****Subject**:**Re: [ferret_users] ceil, floor, and round****From**:**Ge Peng <gpeng@xxxxxxxxxxxxxxxxxxxxxxx>**- Date: Wed, 30 Sep 2009 14:37:48 -0700
- Importance: Normal
- In-reply-to: <Pine.LNX.4.64.0909301226320.16339@atw>
- References: <web-8791555@xxxxxxxxxxxxxxxxxxxxxx> <bbc45a60c42aee6ad3e72feb937742e9.squirrel@xxxxxxxxxxxxxxxxxxxxxxxxxxx> <20090929.155434.208916082.furue@xxxxxxxxxx> <Pine.LNX.4.64.0909301226320.16339@atw>
- Sender: owner-ferret_users@xxxxxxxx
- User-agent: SquirrelMail/1.4.18-1.3.14

Ryo and Andrew: Thanks for your reply. I have tried Andrew's solution and it works fine for me. Thanks, --- Peng > 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 >> >

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

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

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

- 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