Thread: Significant Figures and Chemistry

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    241

    Significant Figures and Chemistry

    does anyone know if there are any built in functions in C++ that make using these much easier? also, does anyone know if there are some built in chemistry constants or functions?

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    ostreams like cout have a number of member functions that can format output for you. Some are called manipulators. Others are called flags. One of the manipulators is setprecision(). It indicates the number of significant digits after the decimal point the stream will use with floating point numbers. One of the flags is scientific. It handles floating point numbers in scientific notation. You can set flags when opening streams or with use of the setf() function. Here's an example that I think should work;

    double example = 623456789;
    cout << setprecision(2) << setf(ios::scientific) << example << endl;

    should show 6.23e8 on the screen--if I did my math and my C++ right.

    To my knowledge there are no standard C++ libraries that deal with chemistry like there is one for math. However, I strongly suspect you can find third party libraries with much of what you want, and if you can't do that you can write your own! (eventually)

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    241
    I know about those formating functions, but I was hoping for something that I could use for basic math and find the significant figures automatically. like if


    main()
    {
    float a,b,c;
    a=2.45;
    b=3.1;
    c=a*b;
    }

    this stored 7.6 as c instead of 7.595

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    I am not aware of such a function. Sorry.

Popular pages Recent additions subscribe to a feed