swirl
Guide to OmniMark 9   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
  Related Topics   Other Library Functions  
operator  

ceiling

 
 

Library: Floating point number support (OMFLOAT)
Import: omfloat.xmd
Library: Binary coded decimal (BCD) numbers (OMBCD)
Import: ombcd.xmd
Return type: BCD or float

Returns: If the value is less than zero, it is truncated to the specified precision. If the value is greater than zero, it is rounded up to the nearest multiple of the specified precision.


Declaration

export overloaded float function
   ceiling    value float x
           by value float base optional

export overloaded bcd function
   ceiling    value bcd x
           by value bcd base optional


Purpose

Use ceiling to round up:

If you include the keyword "by" and specify the precision, ceiling will round up to the multiple of the precision you have specified.

If you do not include the keyword "by" and do not specify the precision, ceiling will round up to the next integer whose value is greater than the expression.

For values less than zero, ceiling works like truncate. For values greater than zero, ceiling rounds up to the next whole number greater than or equal to the original value.

Import either omfloat.xmd or ombcd.xmd in your program after deciding whether you want BCD mathematics (excellent for financial calculations) or floating point mathematics (excellent for extremely large numbers).

BCD Example:

Calculate the area of a circle:

  import "ombcd.xmd" unprefixed
  process
      local bcd pi  initial {"3.14179"}
      local bcd radius  initial {"74"}
      local bcd area
  
      set area to ceiling (pi * radius * radius)
      output "area of circle with radius " || "d" % radius || " = " || "d" % area || "%n"

You can specify the precision of the truncation/rounding. The following program uses a precision of 0.01 to truncate/round the value at the whole cents position:

  import "ombcd.xmd" unprefixed
  process
      local bcd exchange-rate initial {1.4356}
      local bcd us-price  initial {129.95}
      local bcd canadian-price
  
      set canadian-price to ceiling (us-price*exchange-rate) by bcd 0.01
      output "US " || "<$,NNZ.ZZ>" % us-price || " is at most " || "<$,NNZ.ZZ>" % canadian-price || " CDN %n"

The precision specifier must be a power of 10.

Floating Point Example:

Calculate the area of a circle:

  import "omfloat.xmd" unprefixed
  process
      local float radius initial {"74"}
      local float area
  
      set area to ceiling (pi * radius * radius)
      output "Area of circle with radius " || "d" % radius || " is at most " || "d" % area || "%n"

    Related Topics
 
Other Library Functions
 
 

Top [ INDEX ] [ CONCEPTS ] [ TASKS ] [ SYNTAX ] [ LIBRARIES ] [ LEGACY LIBRARIES ] [ ERRORS ]

OmniMark 9.1.0 Documentation Generated: September 2, 2010 at 1:38:10 pm
If you have any comments about this section of the documentation, please use this form.

Copyright © Stilo International plc, 1988-2010.