Problem I used the following code: #include<vector> class UltrasonicRecorder { public: UltrasonicRecorder(int referenceValue, Input referenceInput) : _referenceValue(referenceValue), _referenceInput(referenceInput) {} std::vector<int> […]
Tag: floating-point
string to double
Problem I’m trying to write a function to replace the standard std::stod(…). I want to parse the following valid inputs: […]
getfloat, the floating point analog of getint
Problem Write getfloat, the floating-point analog of getint. What types does getfloat return as its function value? gefloat would also […]
BigDecimal class with arbitrary precision
Problem I recently came across a need to display very large decimal numbers and realized that I could use a […]
Conversion from string to long double
Problem This is a follow up to https://codereview.stackexchange.com/questions/272333/conversion-from-long-double-to-string where I do the reverse conversion. This time around it is string […]
An IEEE half-float implementation in python similar to array.array, is there any way I could make this more efficient?
Problem I’ve written this class to wrap a collection of bytes and interpret them as 16-bit floats. It’s supposed to […]
Computing the integer square root of large numbers
Problem The “integer square root” of a non-negative integer n−−√ n : 9223371982334239233−−−−−−−−−−−−−−−−−√≈3037000490.9999996957524364127605120353 9223371982334239233≈3037000490.9999996957524364127605120353 (computed with PARI/GP). The following implementation […]
Divide two numbers, then apply a custom rounding rule
Problem If the fractional part of the number is greater than 0.6, round up; if less, round down. I need […]
C program to convert string to floating point
Problem From K&R: Extend atof to handle scientific notation of the form 123.45e-6 where a floating-point number may be followed […]
Creating indexes from a theoretical decimal/int, splitting into before and after arrays
Problem I’m currently populating before and after arrays with indexes, based on a number provided. If the input going in […]