#### Category : numbers

I got double type value as int form like no decimal digit. But when I typecast that value to int, the value reduces by 1. Like, val of type double, on calculation comes out to be 4. But when I typecast (int)val, then val becomes 3. I believe there is some interesting answers for this. ..

to practice C++ i decided to write a modulo function. but it returns -nan(ind) how can i make it that the return is the rest of the division? #include <iostream> #include "Header.h" double modulo(double number1, double number2) { double intermediate_result_1=5; double result; int counter = 0; while (intermediate_result_1 < number1) { counter++; intermediate_result_1 = number2 ..

I was reading about the strict Aliasing and stopped on citation saying : An object shall have its stored value accessed only by an lvalue expression that has one of the following types: a type compatible with the effective type of the object. at the first place I was thinking that int and float are ..

I’m trying to implement a combined linear congruential generator (CLCG) on myself for a school-project. Whereas i did implement successfully a single LCG, i do not understand what is the problem in combining them. Single LCG: #include<iostream> #include<climits> #include<cmath> #include<ctime> #include<fstream> // See: https://en.wikipedia.org/wiki/Linear_congruential_generator#LCG_derivatives //Numerical Recipes Parameters #define A 1664525 #define C 1013904223 #define POW232 ..

I am trying to strtol like this: bool is_number(const std::string &s, int &result) { char *p; result = strtol(s.c_str(), &p, 10); return ? } But how can I fix my funtion to handle errors too? I read 5+ articles and it seems there is yet no clear-short answer for this problem. Source: Windows Que..

I’m trying to calculate 2 ** 128 with c++, but it overflows, and I get a value of 0. any ideas on how to calculate this?? I also need to get it on a terminal, but iostream and stdio.h do not support one I tried called __int128. #include <cstring> int main(){ unsigned __int128 a = ..

I’m in C++ and I’m using the exponential function exp() from <cmath>. I’m dealing with very small number, so I tried to use also expl() fucntion, but the (incorrect) result is always the same: 1. I show you a very quick example. How can I solve this problem? Thanks. #include <cmath> … long double a= ..