[fpc-pascal] round(2.5)=2

Sven Barth pascaldragon at googlemail.com
Wed Jun 13 11:22:48 CEST 2018


Wolf <wv99999 at gmail.com> schrieb am Mi., 13. Juni 2018, 09:27:

> Why not ask the CPU to do the rounding? This is what Intel offers in
> volume 1 of the Intel ® 64 and IA-32 Architectures Software Developer's
> Manual:
> 4.8.4.1
>  Rounding Control (RC) Fields
> In the Intel 64 and IA-32 architectures, the rounding mode is controlled
> by a 2-bit rounding-control (RC) field
> (Table 4-8 shows the encoding of this field). The RC field is implemented
> in two different locations:
>>  x87 FPU control register (bits 10 and 11)
>>  The MXCSR register (bits 13 and 14)
> Although these two RC fields perform the same function, they control
> rounding for different execution environ-
> ments within the processor. The RC field in the x87 FPU control register
> controls rounding for computations
> performed with the x87 FPU instructions; the RC field in the MXCSR
> register controls rounding for SIMD floating-
> point computations performed with the SSE/SSE2 instructions.
>
> Do you want more?
>

Which is what FPC already provides with SetRoundMode() in unit Math.

As long as one changes the rounding mode only locally for some calculations
and restores it afterwards there should be no problem (the rounding mode
can be considered as thread specific as well).

Regards,
Sven

PS: please don't add images as inline content, the archive can't display
them correctly.

> <http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20180613/0faff51a/attachment.html>


More information about the fpc-pascal mailing list