#### Category : floating-point

I want to get every digit from a float, but I don’t want to convert it to a string because is ineffective, because float -> string conversion probably is doing it under the hood (e.g. I found that int -> string is doing exactly that). I am looking for directions for doing it effectively. Question ..

Meaning, in a "normal" situation where the performance loss of type promotion is irrelevant, where nobody checks for equality on a float and where nobody declares anything funny like f(float x) {/*do something*/}; f(double x) {/*do something else*/}; and so on. I am aware that the general question of "C++ f suffix why?" has been ..

Using long double arithmetic in C++, the number 50,000,056,019,485.52605438232421875 squared yields 2,500,005,601,951,690,788,240,883,712. Meanwhile, the number 50,000,056,019,485.526050567626953125 (which differs from the first number by less than 0.001) squared yields 2,500,005,601,951,690,787,704,012,800, which differs from the first square by almost 1 billion. With the differences highlighted: 50,000,056,019,485.526054382324218750 ^ 2 = 2,500,005,601,951,690,788,240,883,712 50,000,056,019,485.526050567626953125 ^ 2 = 2,500,005,601,951,690,787,704,012,800 Long double’s ..

I am writing some code that needs to represent small (non-zero) probabilities in C++. The code will contain some basic arithmetics (adding and multiplying) with these probabilities. I am aware of (some of) the numerical subtleties that come with representing small numbers (see e.g. Representing probability in C++). I hence was thinking of storing the ..

I have a function that takes in an optional distance parameter dist, but my algorithm works with squared distances. If the user does not specify any value, I want dist to be as large a number as possible. Result foo(double dist = std::sqrt(std::numeric_limits<double>::max())) const; Is the code above safe, or will it blow up because ..

I have a problem with std::stod and std::stof. Whenever I try to convert any string contains float number as a text always decimal part is just cutted. This code float d = std::stof(splittedLine.at(1)); where splittedLine.at(1) is "77.6482" gives me always 77. How to achieve proper value of this string? I need to pass it later .. I have included the following headers in my simple opengl program: #include <math/math.h> #include <math/vector.h> #include <math/matrix.h> Within my program I want to normalize some vectors as follows: float3 myvec = float3(1.0f, 2.0f, 3.0f); float3 norm = math::normalize(myvec); Doing this gives me several errors: E0304 no instance of overloaded function "math::normalize" matches the argument list ..