Skip to main content
Share Your Experience: Take the 2024 Developer Survey
12 votes
Accepted

A function to convert 0-2000 milliseconds to a double representing a fraction of a second

random garbage in initial word // fakeDouble is expected to be {0, 0} This is insanity. The code needs to implement this comment. Either ...
J_H's user avatar
  • 27.6k
11 votes

A function to convert 0-2000 milliseconds to a double representing a fraction of a second

Code fails every time With ms == 0, code can return a non-zero fake double due to unassigned fakeDouble[]. Non-zero ...
chux - Reinstate Monica's user avatar
11 votes

A function to convert 0-2000 milliseconds to a double representing a fraction of a second

Missing header uint32_t is not defined - we need to include <stdint.h> for this to compile. Unit tests The tests are ...
Toby Speight's user avatar
  • 75.9k
8 votes
Accepted

An is_integer Template Function Implementation in C++

This is wrong for several reasons. What do you mean by "is an integer"? There are many ways to interpret the assertion that some number "is an integer". Do you mean it's an integer ...
G. Sliepen's user avatar
  • 57.1k
6 votes

Computing the square root of a 64-bit integer

Your code is OK for prime sieving. If the rounding mode is nearest-ties-to-even and std::sqrt is correctly rounded (as required by IEEE 754), your code returns \$\...
Řrřola's user avatar
  • 161
4 votes
Accepted

Calculate the maximum number of decimal places with which all floating point numbers can be represented in a range in C++

Precision vs digits While the decimal representation of a floating point number might result in a certain number of digits, that's not the same as the precision of the floating point number itself. ...
G. Sliepen's user avatar
  • 57.1k
3 votes
Accepted

Solving round number in JS by using String

document the return value round(number, decimalsLength) { The name suggests something similar to this documented function: Math.round() The Math.round() static ...
J_H's user avatar
  • 27.6k
3 votes

An is_integer Template Function Implementation in C++

The tests miss most of the important cases The tests only consider a small range of inputs. In particular, we're not testing any of the following possible inputs: doubles with zero fractional part: <...
Toby Speight's user avatar
  • 75.9k
3 votes

Demonstrate effects of summation order

Tree pairwise can be written in a more functional style The "tree pairwise" function can be rewritten to use ranges and views to get the same result, avoiding the need to deal with two ...
G. Sliepen's user avatar
  • 57.1k
2 votes

Demonstrate effects of summation order

I found it amusing to sweep through multiple affine transforms. With denominators of 11 and 17 we see identical error in both ...
J_H's user avatar
  • 27.6k
1 vote

Solving round number in JS by using String

Questionable goal Code suffers from/abuses double rounding. Javascript numbers use binary64 encoding. That provides about 1019 different values. 10.395 is not one of them as it is not a dyadic ...
1 vote

Computing the square root of a 64-bit integer

An alterative to risking floating point issues is to perform an integer based square root: C based code ...
chux - Reinstate Monica's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible