Float Limit (Small)


Program Listing

FloatLimitSmall.cpp

/************************************************************************
*                                                                       *
*   Program:    Float Limit Small                                       *
*                                                                       *
************************************************************************/

#include <iostream.h>
#include <string>

using namespace std;

int main() {

//  Print some small floats

    float x = 0.1;
    cout << x << endl;      // Print 0.1
    x = x * 0.1;
    cout << x << endl;      // Print 0.01
    x = x * 0.1;
    cout << x << endl;      // Print 0.001
    x = x * 0.1;
    cout << x << endl;      // Print 0.0001
    x = x * 0.1;
    cout << x << endl;      // Print 0.00001

//  Print some really small floats

    x = 1.0e-10;    
    cout << x << endl;      // Print 10^(-10)
    x = x * 1.0e-10;
    cout << x << endl;      // Print 10^(-20)
    x = x * 1.0e-10;
    cout << x << endl;      // Print 10^(-30)
    x = x * 1.0e-10;
    cout << x << endl;      // Print 10^(-40)
    x = x * 1.0e-10;
    cout << x << endl;      // Print 10^(-50)
    x = x * 1.0e-10;
    cout << x << endl;      // Print 10^(-60)
    
    return 0;
}

Sample Run

0.1
0.01
0.001
1e-04
1e-05
1e-10
1e-20
1e-30
9.99995e-41
0
0



Return to Lectures page


e-mail me at robbk@hsc.edu

This page was last modified on Tue Dec 7 16:04:23 1999 .

URL: http://people.hsc.edu/faculty-staff/robbk/Coms261/Examples/FloatLimitSmall.html

Return to Coms 261 home page