swirl Guide to OmniMark 5   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesOMX VariablesErrors
 
     
Operations on mixed data types

You can use any arithmetic or comparison operator on mixed data types (either BCD or floating point with integer and int32).

Mixing data types is possible because the arithmetic and comparison operators are overloaded. This means that the operations are performed on a single data type and all other data types are cast to that type.

To add a BCD to an integer, you must specify a BCD variable.

Example:

  ; This program adds an integer to a BCD number.
  include "ombcd.xin"
  process
      local integer eggs initial {12}
      local bcd powdered-eggs  initial {33.5}
      local bcd egg-total

      set egg-total to eggs + powdered-eggs
      output "Total egg equivalents: "
                  || "d" % egg-total
                  ||  "%n"

OmniMark automatically coerces the integer "eggs" to a BCD before adding it to "powdered-eggs".

You can use the following operators only with BCD or floating point numbers:

For operations with BCD numbers, include the library by inserting the following line of code at the start of your program:

  include "ombcd.xin"

For operations with floating point numbers, include the library by inserting the following line of code at the start of your program:

  include "omfloat.xin"

You cannot include both the BCD library and the floating point library in the same program.


  ; This program adds mixed data types.
  include "ombcd.xin"
  process
      local integer red-ones initial {0}
      local integer blue-ones initial {0}
      local integer total initial {0}

      local bcd price
      local bcd tax
      local bcd total-price

      local integer foo initial {7}
      local bcd bar

      set red-ones to 43 + 967
      set blue-ones to 4 + 7
      set total to red-ones + blue-ones

      set price to bcd 29 + bcd 0.99
      set tax to bcd 0.076 + bcd 2.873
      set total-price to price + tax

      set bar to bcd foo + 12

There are boundary conditions limiting operations on mixed data types. For example, if you add two integers totalling more than the largest possible integer, and set their result to a BCD in hopes of accommodating the larger total, the operation will fail. The integers get added together as integers first. This operation fails before the total can be cast as a BCD.

       
----

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

Generated: August 11, 2000 at 3:06:25 pm
If you have any comments about this section of the documentation, send email to docerrors@omnimark.com

Copyright © OmniMark Technologies Corporation, 1988-2000.