Mastering E-Prime: Rounding, truncation, floor, ceil

David McFarlane mcfarla9 at msu.edu
Tue May 17 16:36:48 UTC 2011


E-Prime (i.e., VBA) has no functions named "trunc()", "floor()", or 
"ceil()", but as a point of reference we recognize the following 
standard definitions:

- trunc(x) = integer part of x, i.e., x rounded toward 0.
   Note that, e.g., trunc(2.1) = 2, and trunc(-2.1) = -2.
- floor(x) = nearest integer less than or equal to x.
   Note that, e.g., floor(2.1) = 2, while floor(-2.1) = -3.
- ceil(x) = nearest integer greater than or equal to x.
   Note that, e.g., ceil(2.1) = 3, while ceil(-2.1) = -2.

Now, E-Prime does provide the following:

- Fix(x) "returns the integer part of x", i.e., it simply truncates x
   (trunc(x)), i.e., it rounds toward 0.
- Int(x) "returns the integer part of a given value by returning the
   first integer less than the number", i.e., does a floor(x).  (Yes,
   PST's using "integer part" in both descriptions does confuse things.)
- CInt(x) returns an integer for the round value of x (using "bankers'"
   or "scientific" rounding, where values ending in .5 get rounded to the
   the nearest even integer).
- CLng(x) does the same as CInt(x) but returns a Long.
- Format$(x) returns a String (or, Format(x) a String Variant) of x
   according to an optional format specifier string, and may round x
   (using "bankers'" or "scientific" rounding).
- x\y does integer division after first rounding the arguments (using
   "bankers'" or "scientific" rounding), i.e.,
   (x\y) = Fix( CInt(x) / CInt(y) ).

Using these, we may implement ceil(x) with -Int(-x).

-- David McFarlane, Professional Faultfinder

-- 
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To post to this group, send email to e-prime at googlegroups.com.
To unsubscribe from this group, send email to e-prime+unsubscribe at googlegroups.com.
For more options, visit this group at http://groups.google.com/group/e-prime?hl=en.



More information about the Eprime mailing list