How to properly round-up half float numbers?

The Numeric Types section documents this behaviour explicitly: round(x[, n]) x rounded to n digits, rounding half to even. If n is omitted, it defaults to 0. Note the rounding half to even. This is also called bankers rounding; instead of always rounding up or down (compounding rounding errors), by rounding to the nearest even … Read more

PHP7.1 json_encode() Float Issue

This drove me nuts for a bit until I finally found this bug which points you to this RFC which says Currently json_encode() uses EG(precision) which is set to 14. That means that 14 digits at most are used for displaying (printing) the number. IEEE 754 double supports higher precision and serialize()/var_export() uses PG(serialize_precision) which … Read more

Controlling number of decimal digits in print output in R

The reason it is only a suggestion is that you could quite easily write a print function that ignored the options value. The built-in printing and formatting functions do use the options value as a default. As to the second question, since R uses finite precision arithmetic, your answers aren’t accurate beyond 15 or 16 … Read more

Difference between toFixed() and toPrecision()?

toFixed(n) provides n length after the decimal point; toPrecision(x) provides x total length. Ref at w3schools: toFixed and toPrecision EDIT: I learned a while back that w3schools isn’t exactly the best source, but I forgot about this answer until I saw kzh’s, uh, “enthusiastic” comment. Here are additional refs from Mozilla Doc Center for toFixed() … Read more

Is floating-point math consistent in C#? Can it be?

I know of no way to way to make normal floating points deterministic in .net. The JITter is allowed to create code that behaves differently on different platforms(or between different versions of .net). So using normal floats in deterministic .net code is not possible. The workarounds I considered: Implement FixedPoint32 in C#. While this is … 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

What’s the difference between a single precision and double precision floating point operation?

Note: the Nintendo 64 does have a 64-bit processor, however: Many games took advantage of the chip’s 32-bit processing mode as the greater data precision available with 64-bit data types is not typically required by 3D games, as well as the fact that processing 64-bit data uses twice as much RAM, cache, and bandwidth, thereby … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)