Product Documentation
Virtuoso Parameterized Cell SKILL Reference
Product Version IC23.1, August 2023

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

n_num

Any number you want to convert.

f_precision

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.

Default: 0.001

Value Returned

x_result

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 CDS.log file for a message about the error.

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:

When x equals

pcFix( x ) returns

14.998

14.0

14.999

15.0

15.0

15.0

15

15.0

15.998

15.0

15.999

16.0

The following shows the results of specifying the optional f_precision argument:

When x equals

And f_precision equals

Then pcFix returns

14.998

0.001

14

14.998

0.005

15

14

0.001

14

14

0.005

14

14.0

0.001

14

14.0

0.005

14

14.999

0.0001

14

14.999

0.001

15

Related Topics

pcRound

pcExprToString

pcTechFile

Recommended, Supported SKILL Functions for Pcells


Return to top
 ⠀
X