Trigonometry Sin rule calculation problem

This is a discussion on Trigonometry Sin rule calculation problem within the C++ Programming forums, part of the General Programming Boards category; Code: #define PI 3.14159265 #include <stdio.h> #include <math.h> void main(void){ double angleB = 180.00000000000; double L1; L1 = sin(angleB*PI/180); printf("%f", ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    1

    Angry Trigonometry Sin rule calculation problem

    Code:
    #define PI 3.14159265
    
    #include <stdio.h>
    #include <math.h>
    
    void main(void){
    	double angleB = 180.00000000000;
    	double L1;
    	L1 = sin(angleB*PI/180);
    	printf("%f", L1);
    }

    in the console, printf, prints 0.000000 (as expected)
    when I hover over L1 it reads, 3.5897934739268e-009
    Which then screws up the rest of my calcuations. Can someone tell me why this is so?

    Ta

    Harry

    (Visual C++ 6.0) - For those who don't know sin(180) should = 0 ..

  2. #2
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    i dont know what you mean by hover, this code works fine for
    me on the same compiler. I assume that you want to be able
    to enter in a number and get its sin, you'll need this code:

    scanf ("%lf", &angleB);

    i think that there's something about the %lf format specifier being
    removed in the last standard, (it might just be for printf), but
    scanning in using just %f doesnt work in visual.

    by the way, whats with all the trailing 0's on angleB? NO NEED!
    and use int main instead of void main, there's a discussion on this
    section of the forum on the topic, check it out to see whats wrong
    with void.

    lastly, this is the C++ forum, printf implies that you're doing C,
    not much of a difference in this code, just so you know to post
    on the correct forum.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  3. #3
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Quote Originally Posted by Harry
    Can someone tell me why this is so?
    3.14159265 is not the value of pi.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    > in the console, printf, prints 0.000000 (as expected)
    > when I hover over L1 it reads, 3.5897934739268e-009
    Note the e-009
    That's 0.0000000035897934739268
    Which if you only display the first 6 digits is 0.000000

    > Which then screws up the rest of my calcuations. Can someone tell me why this is so?
    Floats are inaccurate, your calculations need to take the fact that floats are approximations into account. This means not assuming for instance that any two floats will compare equal for example.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 12-03-2003, 05:47 PM
  2. Double calculation problem
    By Coconut in forum C Programming
    Replies: 6
    Last Post: 10-08-2002, 08:38 PM
  3. HELP!!! Calculation problem!
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 06-14-2002, 12:09 PM
  4. Multithreading & Problem :: MFC
    By kuphryn in forum Windows Programming
    Replies: 1
    Last Post: 06-06-2002, 01:33 PM
  5. problem with output
    By Garfield in forum C Programming
    Replies: 2
    Last Post: 11-18-2001, 08:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21