|
||
|
GP Mailing List
ATXGPSIG List
|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: Some trig trouble -- and IEEE floating point format
You guys do know that the sin() functions is math.h only accept an angle in
radians right? To convert a degree angle to radians just use this
conversion factor:
pi
(degrees) X ---------------
180 degrees
----- Original Message -----
From: "slick willy" <bporter@flashcom.net>
To: <gameprogrammer@gameprogrammer.com>
Sent: Tuesday, September 05, 2000 6:02 PM
Subject: Re: Some trig trouble -- and IEEE floating point format
> unless your angle_deg is not a double, then i dont see a problem with the
> code. however, you could always try sind(double x) or sindf(float x) which
> both take an angle in degrees as their argument.
>
> --Bill
>
> ----- Original Message -----
> From: "Lionel Pinkhard" <lionelp@worldonline.co.za>
> To: <gameprogrammer@gameprogrammer.com>
> Sent: Tuesday, September 05, 2000 3:31 PM
> Subject: Some trig trouble -- and IEEE floating point format
>
>
> > Hey guys/gals,
> >
> > I got some trouble with a simple procedure to convert degrees into
> > radians, and then calculate the sine of the angle, here's my code (with
a
> > 'printf' for diagnostics -- value is in angle_deg):
> >
> > double angle_rad, sine;
> >
> > angle_rad = angle_deg * M_PI / 180.0;
> > sine = sin(angle_rad);
> >
> > printf("The sine of %.2f is %.8f.\r\n", angle_deg, sine);
> >
> > If I try to run this code, I get "Floating point error: Domain.",
> > "Abnormal program termination". What am I doing wrong? I have an idea
it's
> > something really simple.
> >
> > Next, a little problem with pointers:
> >
> > I'm using pointers to return the movement from the joystick:
> >
> > Function:
> > void joy_movement(signed char *x, signed char *y) {
> > unsigned short absx, absy;
> > signed char deltax, deltay;
> >
> > joy_absolute(&absx, &absy);
> >
> > << rest of code here >>
> >
> > *x = deltax;
> > *y = deltay;
> > }
> >
> > Program:
> > joy_movement(&x, &y);
> >
> > joy_movement is a function to get the movement from the joystick in the
> > range -127 to 128 (that's why I'm using a char). joy_absolute is a
> > function to return the axises of the joystick, and is in the same format
> > as joy_movement. When I compile I get the 'unportable pointer' messages,
> > and the functions don't work.
> >
> > Hope somebody can help me out here!
> >
> > Nextly, somebody asked about floating point numbers, well for
> > single-precision (4 bytes), the sign takes 1 bit, the exponent takes 8
> bits and
> > the mantissa uses the other 23 bits (the number is 32-bit). For
> > double-precision (8 bytes), the sign takes 1 bit, the exponent takes 11
> > bits and the mantissa uses the other 52 bits (the number is 64-bit). I'm
> > not sure about how correct this is, but try printing out a float in
> > hexadecimal or something (I'm not sure whether that is possible, can
> > somebody help me out there?) Anyways, this is the IEEE format, there are
> > also other formats, such as Microsoft's format, but I think that's
> > obsolete by now.
> >
> > Ciao,
> >
> > Lionel
> >
> > =================================================================
> > The GameProgrammer.Com mailing list is for the open discussion
> > of any topic related to the art, science, and business of
> > programming games. This list is especially tolerant of beginners.
> > We were all beginners once
> >
> > To SUBSCRIBE or UNSUBSCRIBE please visit:
> > http://gameprogrammer.com/mailinglist.html
> >
> >
>
> =================================================================
> The GameProgrammer.Com mailing list is for the open discussion
> of any topic related to the art, science, and business of
> programming games. This list is especially tolerant of beginners.
> We were all beginners once
>
> To SUBSCRIBE or UNSUBSCRIBE please visit:
> http://gameprogrammer.com/mailinglist.html
>
>
=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once
To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html
|
|