SetRoundMode
Deutsch · English
With math.setRoundMode you can set the FPU’s method of rounding. If no FPU is present, the global variable system.softFloat_rounding_mode will determine the rounding mode for floating-point operations implemented by software.
This also affects the run-time behavior of the round function. (Note, constant expressions can and will be evaluated during compile-time, thus the presented techniques do not affect compile-time results.)
invocation
SetRoundMode resides in the math unit. You need to include the math unit in the uses clause.
SetRoundMode is a unary function. The function’s signature reads:
function setRoundMode(const roundMode: TFPURoundingMode): TFPURoundingModeThe following values are permissible for roundMode (cf. TFPURoundingMode):
rmNearest
rounds to the nearest even integer (Banker‘s Rounding: 0.5 rounds down to 0; 1.5 rounds up to 2). This is the default.
rmDown
generally rounds to the next smaller integer
rmUp
generally rounds to the next larger integer
rmTruncate
cuts off the decimal places
The function will return the previous rounding mode, before it was changed. Thus, it returns the same value as math.getRoundMode.
Warning: The setting of the rounding mode applies to all internal floating point calculations. In particular, it determines how numbers that cannot be represented exactly as the native floating-point type’s values are to be rounded to the internal representation within the scope of the available bits. Therefore, the usage of
setRoundModefor general rounding purposes is not recommended.
see also
From the Free Pascal wiki, page "SetRoundMode", as it stood on 2020-05-21 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
