What’s the difference between hard and soft floating point numbers?

Hard floats use an on-chip floating point unit. Soft floats emulate one in software. The difference is speed. It’s strange to see both used on the same target architecture, since the chip either has an FPU or doesn’t. You can enable soft floating point in GCC with -msoft-float. You may want to recompile your libc … Read more

Fixed-size floating point types

Nothing like this exists in the C or C++ standards at present. In fact, there isn’t even a guarantee that float will be a binary floating-point format at all. Some compilers guarantee that the float type will be the IEEE-754 32 bit binary format. Some do not. In reality, float is in fact the IEEE-754 … Read more

Why is SSE scalar sqrt(x) slower than rsqrt(x) * x?

sqrtss gives a correctly rounded result. rsqrtss gives an approximation to the reciprocal, accurate to about 11 bits. sqrtss is generating a far more accurate result, for when accuracy is required. rsqrtss exists for the cases when an approximation suffices, but speed is required. If you read Intel’s documentation, you will also find an instruction … Read more

How to perform division in Go

The operands of the binary operation 3 / 10 are untyped constants. The specification says this about binary operations with untyped constants if the operands of a binary operation are different kinds of untyped constants, the operation and, for non-boolean operations, the result use the kind that appears later in this list: integer, rune, floating-point, … Read more

What is float in Java?

In Java, when you type a decimal number as 3.6, its interpreted as a double. double is a 64-bit precision IEEE 754 floating point, while floatis a 32-bit precision IEEE 754 floating point. As a float is less precise than a double, the conversion cannot be performed implicitly. If you want to create a float, … Read more

Convert float to string with precision & number of decimal digits specified?

A typical way would be to use stringstream: #include <iomanip> #include <sstream> double pi = 3.14159265359; std::stringstream stream; stream << std::fixed << std::setprecision(2) << pi; std::string s = stream.str(); See fixed Use fixed floating-point notation Sets the floatfield format flag for the str stream to fixed. When floatfield is set to fixed, floating-point values are … Read more