Extreme numerical values in floating-point precision in R

R uses IEEE 754 double-precision floating-point numbers. Floating-point numbers are more dense near zero. This is a result of their being designed to compute accurately (the equivalent of about 16 significant decimal digits, as you have noticed) over a very wide range. Perhaps you expected a fixed-point system with uniform absolute precision. In practice fixed-point … Read more

In MATLAB, are variables REALLY double-precision by default?

They’re doubles. vpa() is simply choosing to display non-significant digits beyond the floating point relative accuracy, where printf() and disp() truncate or zero them out. You’re only getting your original four digits back out because the literal you chose to initialize num with just happens to be the exact decimal expansion of a binary double … Read more

Why is a round-trip conversion via a string not safe for a double?

I found the bug. .NET does the following in clr\src\vm\comnumber.cpp: DoubleToNumber(value, DOUBLE_PRECISION, &number); if (number.scale == (int) SCALE_NAN) { gc.refRetVal = gc.numfmt->sNaN; goto lExit; } if (number.scale == SCALE_INF) { gc.refRetVal = (number.sign? gc.numfmt->sNegativeInfinity: gc.numfmt->sPositiveInfinity); goto lExit; } NumberToDouble(&number, &dTest); if (dTest == value) { gc.refRetVal = NumberToString(&number, ‘G’, DOUBLE_PRECISION, gc.numfmt); goto lExit; } DoubleToNumber(value, … Read more

Set back default floating point print precision in C++

You can get the precision before you change it, with std::ios_base::precision and then use that to change it back later. You can see this in action with: #include <ios> #include <iostream> #include <iomanip> int main (void) { double d = 3.141592653589; std::streamsize ss = std::cout.precision(); std::cout << “Initial precision = ” << ss << ‘\n’; … Read more

What does “real*8” mean?

The 8 refers to the number of bytes that the data type uses. So a 32-bit integer is integer*4 along the same lines. A quick search found this guide to Fortran data types, which includes: The “real*4” statement specifies the variable names to be single precision 4-byte real numbers which has 7 digits of accuracy … Read more