#### Category : double

Regarding performance of double vs long double: On Macbook, Core i7 2017, MacOs 11, Xcode 12.2, C++17, Clang, with and without optimization i get these measurements: long int N = 1e8; double x = 0; for (long int i = 0; i<N; i++) { x = pow(x,2); } // takes 0.7 sec long double y ..

I am a newbie in c++ and I am quite confused in programmer – defined functions. It shows these errors 40 [Error] cannot convert ‘double’ to ‘double(double, double)’ in assignment 40 [Error] assignment of function ‘double total_area(double, double)’ I cannot enter total_area = cross_area + side_area; If i try to remove the double, it results ..

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

I am a complete beginner(2 days of learning) and I realized that when I apply this algorithm(which is an algorithm to calculate the height of a right triangle) #include<iostream> #include<cmath> using namespace std; int main() { int c1,c2,i,x; float h; cin>>c1>>c2>>i; h=(c1*c2)/i; x=h*100; h=x/100; cout<<h; return 0; } A friend of mine told me to ..

I’m trying to use the static_cast that seems simple but I can’t figure out what I’m doing wrong. I have the class Rat (used to represent rational numbers) and I want to cast it to a double. Then I could do double x = Rat(2,3) (it would store 2/3 into the x). To do that ..

I’ve been making a Height prediction calculator but i have been given an error when compiling #include <iostream> #include <string> using namespace std; int main() { int i = 0; do { double mom; double dad; string boygirl; double fullboy = (mom * 13 / 12 + dad) / 2; double fullgirl = (dad + ..

Code image In the code that I have written I am getting the sum of 2.0 and 3.0 as 5 and not 5.0. What should I do to get the desired output? Source: Windows Que..