MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Ceiling and Floor function

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> TSO and ISPF
View previous topic :: View next topic  
Author Message
danm
Intermediate


Joined: 29 Jun 2004
Posts: 170
Topics: 73

PostPosted: Wed Apr 23, 2008 8:48 am    Post subject: Ceiling and Floor function Reply with quote

I can't find a ceiling or floor buildin function in REXX.
Code:

Example:
  data = 1.00000...1   to  2              Ceiling returns 2
  data = 1             to   1.9999....    Floor returns 1

I can create the ceiling and floor function with 3 buildin functions: 
  format(data + word('.5 0',1+datatype(data,'W')),,0)      <-- Ceiling
  format(data + word('-.5 0',1+datatype(data,'W')),,0)     <-- Floor


Anyone has a more efficient solution?
Back to top
View user's profile Send private message
semigeezer
Supermod


Joined: 03 Jan 2003
Posts: 1014
Topics: 13
Location: Atlantis

PostPosted: Wed Apr 23, 2008 11:42 am    Post subject: Reply with quote

I forget how negative #s should be treated, but I think this will do it:
Code:
parse arg a
say floor(a)
say ceil(a)
return
floor: return arg(1)%1-(sign(arg(1)//1)=-1)
ceil: return -floor(-a)

_________________
New members are encouraged to read the How To Ask Questions The Smart Way FAQ at http://www.catb.org/~esr/faqs/smart-questions.html.
Back to top
View user's profile Send private message Visit poster's website
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Wed Apr 23, 2008 2:40 pm    Post subject: Reply with quote

danm,

you can try this

Code:

FLOOR: procedure
parse arg F
return TRUNC(F) - (F < 0) * (F <> TRUNC(F))
 
CEILING: procedure
parse arg C
return TRUNC(C) + (C > 0) * (C <> TRUNC(C))

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
warp5
Intermediate


Joined: 02 Dec 2002
Posts: 429
Topics: 18
Location: Germany

PostPosted: Thu Apr 24, 2008 1:24 am    Post subject: Reply with quote

Are you talking about the max and min functions of rexx?
Back to top
View user's profile Send private message Visit poster's website
danm
Intermediate


Joined: 29 Jun 2004
Posts: 170
Topics: 73

PostPosted: Fri Apr 25, 2008 11:20 am    Post subject: Reply with quote

warp5,

No, I am not talking max or min function. I want to round up or round down to the nearest integer after a calculation. Example: If the calculated value is 2.5, ceiling returns 3, floor returns 2.
Back to top
View user's profile Send private message
warp5
Intermediate


Joined: 02 Dec 2002
Posts: 429
Topics: 18
Location: Germany

PostPosted: Mon Apr 28, 2008 1:02 am    Post subject: Reply with quote

Well, you could easily create such a function by adding or subtracting 0.5 and then truncating the decimal.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> TSO and ISPF All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group