Sign in Join
Wiki copytemporary

SetRoundMode: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-With [`math.setRoundMode`](https://www.freepascal.org/docs-html/rtl/math/setroundmode.html) you can set the <abbr title="Floating Point Unit">FPU</abbr>’s method of rounding. If no FPU is present, the global variable [`system.softFloat_rounding_mode`](https://www.freepascal.org/docs-html/rtl/system/softfloat_rounding_mode.html) will determine the rounding mode for floating-point operations implemented by software.
1+With [`math.setRoundMode`](https://www.freepascal.org/docs-html/rtl/math/setroundmode.html) you can set the FPU’s method of rounding. If no FPU is present, the global variable [`system.softFloat_rounding_mode`](https://www.freepascal.org/docs-html/rtl/system/softfloat_rounding_mode.html) will determine the rounding mode for floating-point operations implemented by software.
22
33This 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.)
44
55## invocation
66
77`SetRoundMode` resides in the [`math` unit](https://www.freepascal.org/docs-html/rtl/math/index.html). You need to include the `math` unit in the [[Uses|uses clause]].
88
99`SetRoundMode` is a unary function. The function’s signature reads:
1010
1111``` pascal
1212function setRoundMode(const roundMode: TFPURoundingMode): TFPURoundingMode
1313```
1414
1515The following values are permissible for `roundMode` (cf. [`TFPURoundingMode`](https://www.freepascal.org/docs-html/rtl/system/tfpuroundingmode.html)):
1616
1717`rmNearest`
1818rounds to the nearest *even* integer (Banker‘s Rounding: `0.5` rounds down to `0`; `1.5` rounds up to `2`). This is the default.
1919
2020`rmDown`
2121generally rounds to the next smaller integer
2222
2323`rmUp`
2424generally rounds to the next larger integer
2525
2626`rmTruncate`
2727cuts off the decimal places
2828
2929The function will return the previous rounding mode, before it was changed. Thus, it returns the same value as [`math.getRoundMode`](https://www.freepascal.org/docs-html/rtl/math/getroundmode.html).
3030
3131> **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 `setRoundMode` for general rounding purposes is not recommended.
3232
3333## see also
3434
3535- [[Round|round]]
3636- [[Int|int]]
3737- [[Trunc|trunc]]
3838
3939---
4040*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](/wiki-contact).*
4141Category: Pascal

Back to history