pcFix
pcFix(n_num[f_precision] ) =>x_result
Description
Converts a number to an integer in the format fixnum. When n_num is close to a whole number, the system keeps the integer part of the number and adds a single decimal place equal to zero. Here, close means the value of the number is within the range of plus or minus the value of f_precision of the integer part of the number specified by n_num. When the value is not within this range, the function allows the system to use the value in the first decimal place to round the n_num to an integer in the format number.0; the system ignores all other decimal places. This function is useful for correcting the round-off approximation that can occur with floating-point numbers that are stored in 32 or 64 bits.
Arguments
|
Floating-point number specifying number of decimal places to the right of the decimal point to use as a range for determining whether n_num is close to a whole number. |
Value Returned
|
A number with one decimal place that is equal to zero. If n_num does not contain a number, an error occurs; look in the CIW or at the |
Examples
If you want to test for the condition x equals 6.0, you need to use pcFix to correct a possible rounding problem that could occur with a floating-point number. Otherwise, your condition might never be satisfied, because x might never be equal to 6.0; instead, it might be a close value, such as 5.999999.
The following code shows how to use pcFix to correct floating-point rounding errors:
if( pcFix( x ) == 6.0
; perform conditional operations here
) ;endif
If you used the code shown below instead, your condition might never be satisfied:
x = 6.0
if ( x == 6.0
; perform conditional operations here
) ;endif
Additional Information
If the condition you want to test is x = 15.0, use the pcFix function to ensure that results in the range from 14.999 to 15.999 are converted to 15.0. This implies the following:
The following shows the results of specifying the optional f_precision argument:
Related Topics
Return to top