Thread: Euler's number

  1. #1
    Registered User
    Join Date
    May 2007

    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:

    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:

    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.

  2. #2
    Registered User
    Join Date
    Oct 2005
    The "e" in this case symbolizes exponentiation, and not euler's number.

    If you want euler's number in C++, you have to
    #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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf oddities
    By robwhit in forum C Programming
    Replies: 5
    Last Post: 09-22-2007, 01:03 AM
  2. Calculating next prime number
    By anilemon in forum C Programming
    Replies: 8
    Last Post: 04-17-2006, 10:38 AM
  3. Prime number program problem
    By Guti14 in forum C Programming
    Replies: 11
    Last Post: 08-06-2004, 04:25 AM
  4. parsing a number
    By juancardenas in forum C Programming
    Replies: 1
    Last Post: 02-19-2003, 01:10 PM
  5. Random Number problem in number guessing game...
    By -leech- in forum Windows Programming
    Replies: 8
    Last Post: 01-15-2002, 05:00 PM