|
|||||
|
||||||
Related Syntax | Other Library Functions |
operator |
sqrt |
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: The square root of either a floating point number or BCD number. For floating point, if x < 0, returns NaN.For BCD, if x < 0, throws an exception. |
define overloaded external float function sqrt value float x define overloaded external bcd function sqrt value bcd x
Use sqrt to calculate the square root of either
You must import either omfloat.xmd or ombcd.xmd in your program. Decide whether you want BCD mathematics (excellent for financial calculations) or floating point mathematics (excellent for extremely large numbers).
; Displays the square root of 144 as a floating point number. import "omfloat.xmd" unprefixed process local float x initial {"144"} local float result set result to sqrt x output "result = " || "d" % result || "%n"
; Displays the square root of 144 as a BCD number. import "ombcd.xmd" unprefixed process local bcd x initial {"144"} local bcd result local bcd rounded-result set result to sqrt x set rounded-result to round result bankers-nearest 0.01 output "The square root of " || "d" % x || " = " || "d" % rounded-result || "%n" ; Output: "The square root of 144 = 12"
If you take the square root of an integer, you need to coerce the integer to a floating point or BCD number so that the appropriate function is called. The result will depend on which square root function is called.
In an OmniMark program, always surround operators with spaces.
Related Syntax exp ln log10 ** (power) |
Other Library Functions ** (power) abs ceiling exp floor ln log10 round sqrt truncate |
Copyright © Stilo International plc, 1988-2008.