Category : floating-point

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 ..

Read more

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 ..

Read more

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 ..

Read more

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 ..

Read more

In a method like this: vector<uint8_t> Transaction::bytes() { vector<uint8_t> result; … return result; } I need convert a float variable to a vector<uint8_t> (where each byte of the float should be an element of the vector), to allow me add this vector to another: vector<uint8_t> temp; result.insert(result.end(), temp.begin(), temp.end()); Anyone can give a hint of ..

Read more

Thanks for looking into my question, I’m trying to solve a problem for which I’ll have to store float’s in 3 different array’s, surprisingly the values being stored are all zeros, could you point out what’s going wrong here. #include <iostream> #include <iomanip> #include <vector> using namespace std; int main(){ int n,m; cin>>n>>m; vector<float>prb(n+1,0),prft(n+1,0),loss(n+1,0); for(int ..

Read more