-
Euler's number
Hello. I'm fairly new to C++ and I have a question regarding reading in a value containing the number e from a file. Right now, I have an input file from which I am reading in various values. One of these values is 1e -10, which I am simply reading in as a double like this:
Code:
file.get();
file.ignore(100, "=") >> threshold;
where threshold is a double value that is supposed to be 1e -10 once read in. If I do a cout with that value, it prints out 1e -10 to the screen. However, if I try to do any math with it, it treats it as a 0. For instance, I tried to add 5 to it, and when I did a cout, instead of printing out the value of 1e -5 to the screen, it prints out 5.
I also tried to use it in a while loop that looked something like this:
Code:
while(currBest >= threshold){
//my code
}
However, since threshold is being treated as a 0, the loop continues until currBest reaches 0 when it should end when currBest is either still greater than 1e -10 or equal to it.
I'm wondering if there's a #include I'm forgetting or if I'm just doing something wrong.
If anyone can help me out with this, I'd be grateful. :)
-
The "e" in this case symbolizes exponentiation, and not euler's number.
If you want euler's number in C++, you have to
Code:
#include <iostream>
#include <cmath>
int main()
{
std::cout << exp(1.0) << std::endl;
return 0;
}
In your case, "1e-10" would be 0.000000001. Anyway, a one with nine zeros in front of it, below the decimal. If you added five to this, it would be five (for all practical purposes).
So if you intend to use 1e-10 as 0.000... then you can use atof() to convert it to a floating point number. If you intend to use it as 1 * euler's number - 10, then you're going to have to write a function for it.