When can I change the rounding mode of the CPU?

Some articles suggest using the command fistpto quickly convert float-> integer. It depends on the current CPU rounding mode, so you will need to set it.

But can this rounding mode be changed during program execution by other programs? In the OS?

Even worse, is this a possible scenario (pseudo-code)?

set_rounding_mode(ROUND_TRUNCATE);
/* process gets switched out and other process sets the rounding mode to round */
int x = round_with_fistp(0.6);
printf("%d\n", x); // prints 1
+3
source share
1 answer

. , , . , , (, ) , ( ) .

+5

All Articles