Using software floating point on x86 linux

It is surprising that gcc doesn’t support this natively as the code is clearly available in the source within a directory called soft-fp. It’s possible to compile that library manually: $ svn co svn://gcc.gnu.org/svn/gcc/trunk/libgcc/ libgcc $ cd libgcc/soft-fp/ $ gcc -c -O2 -msoft-float -m32 -I../config/arm/ -I.. *.c $ ar -crv libsoft-fp.a *.o There are a … Read more

Having parameter (constant) variable with NaN value in Fortran

To add to Vladimir F’s answer I’ll mention that gfortran 5.0 (but not earlier) supports the IEEE intrinsic modules. Instead of real x x=0 x=0/x one can use use, intrinsic :: iso_fortran_env use, intrinsic :: ieee_arithmetic integer(int32) i real(real32) x x = ieee_value(x, ieee_quiet_nan) i = transfer(x,i) This gives you a little flexibility over which … Read more

How is floating point conversion actually done in C++?(double to float or float to double)

The cvtsd2ss instruction uses the FPU’s rounding mode to do the conversion. The default rounding mode is round-to-nearest-even. In order to follow the algorithm, it helps to keep in mind the information at the IEEE 754-1985 Wikipedia page, especially the diagrams representing the layout. First, the exponent of the target float is computed: the double … Read more

How do you get the next value in the floating-point sequence? [duplicate]

Here are five (really four-and-a-half) possible solutions. Solution 1: use Python 3.9 or later Python 3.9, released in October 2020, includes a new standard library function math.nextafter which provides this functionality directly: use math.nextafter(x, math.inf) to get the next floating-point number towards positive infinity. For example: >>> from math import nextafter, inf >>> nextafter(100.0, inf) … Read more