Machinery's Handbook, 31st Edition
CNC SUBROUTINES AND MACROS 1383 Rounding Functions: Rounding functions control how decimal places are handled. There are three rounding functions: 1) ROUND 2) FIX 3) UP (1) ROUND: The ROUND function rounds off a value to the nearest whole number. The function disregards fractions that are less than 0.5. For fractions that are equal to or greater than 0.5, the next whole number is the rounded value: ROUND[0.00001] Returns 0.0 ROUND[0.5] Returns 1.0 ROUND[0.99999] Returns 1.0 ROUND[1.0] Returns 1.0 There is one very important difference between using the ROUND function directly in a program statement or in a variable definition. Consider the following two blocks: #101 = 27⁄32 G91 G00 X[ROUND[#101]] The incremental motion will be X0.8438 (US customary) or X0.844 (metric). However, if the ROUND function is used in a variable definition, the result will be different: #101 = [ROUND[27⁄32]]Returns 1.0 G91 G00 X[#101] The incremental motion will be X1.0 Rounding can also be performed to a given number of decimal places, but it is a two step process. In the first step, the given value must be multiplied by the factor of: 10... to round off to one decimal place 100... to round off to two decimal places 1000... to round off to three decimal places (typical for metric system) 10000... to round off to four decimal places (typical for US customary system) The second step is to use the ROUND function together with the multiplier. For example, to round 123.56789 to three decimal places: #101 = 123.456789 #101 = #101*1000Returns 123456.789 #101 = ROUND[#101]Returns 123457.0 (nearest whole number) #101 = #101⁄1000Returns 123.457 Note that only a single variable has been used for all four calculations. If the original value is not required later, this is a very efficient method of defining variables in the macro body. The remaining two rounding functions FIX and FUP are used to round a given value up or down only, regardless of whether the decimal portion is over or under 0.5. The FIX and FUP functions are commonly used for counting rather than calculations. (2) FIX: The FIX function is designed to round down the given value (discard fractions less than 1.0) i.e., strip all values after decimal point. ROUND[0.00001] Returns 0.0 ROUND[0.5] Returns 0.0 ROUND[0.99999] Returns 0.0 ROUND[1.0] Returns 1.0 (3) FUP: The FUP function is designed to round up the given value (raise fractions less than 1.0). ROUND[0.00001] Returns 1.0 ROUND[0.5] Returns 1.0 ROUND[0.99999] Returns 1.0 ROUND[1.0] Returns 1.0
Copyright 2020, Industrial Press, Inc.
ebooks.industrialpress.com
Made with FlippingBook - Share PDF online