? c - error?

with this function i set my Surface and the programm always crashed
because of this:

when i write:
double v3x, v3x, v1x

v3x = v1x + v2x;
and
v1x=-2
v2x=2
then my compiler tells me that v3x = -0 but i think it must be 0
!!??

and my second problem is:
how to check if something like this happens ?

if (v3x = -0) doesn’t work !!!
and a check for (v3x = 0) does the same
damn

if someone can help me - PLEASE DO IT

Thank you–
From:
Joachim Schiele
[ http://www.dune2.de || Linux - my way! ]

with this function i set my Surface and the programm always crashed
because of this:

when i write:
double v3x, v3x, v1x

v3x = v1x + v2x;
and
v1x=-2
v2x=2

Just checking the obvious (forgive me if you find this insulting… it’s
not my intention! :wink:

Both v2x and v1x have been initialized to something before this
v3x=v1x+v2x; statement, correct? (I.e., that v1x=-2 and v2x=2 were before
this).

Other than that, I’d recommend putting the actual code somewhere online
and let others look at it… since it is likely something screwy is
happenning elsewhere…On Sat, 24 Jun 2000, Joachim Schiele wrote:


Sam Hart http://www.physics.arizona.edu/~hart/
Web Page Highlights: Video Game History, Black Hole Simulation, & more.
OTHER WEB SITES MAINTAINED BY SAM HART
http://www.geekcomix.com/ - Geekcomix, the Daily Geek Comic Strip Site
http://www.physics.arizona.edu/~hart/gw/ - Ghostworks (Alt./Linux Computing)

when i write:
double v3x, v3x, v1x

v3x = v1x + v2x;
and
v1x=-2
v2x=2
then my compiler tells me that v3x = -0 but i think it must be 0
!!??

On what type of computer are you compiling this? The only thing I can
imagine (and I do not know how to control this) happening is your
computer or c-compiler/library using one-complement signed numbers.
That’s the only explanation I can think of that would create both a 0
and -0 number. Unless someone has a better explanation. :slight_smile:

For fun, try: v3x = v2x + v1x, with v1x = -2 and v2x = 2. If that one
comes up with 0 my rambling might be true. :slight_smile:

Regards,

Pieter Hulshoff

thank you for answering my question but - i tried it and it got the
same out "-0.00000"
everything is correct but this won’t work

i use :
-linux redhat 6.1
-gcc v??
-SDL 1.1.3

the problem seems to be there with every version of SDL - no wonder -
doesn’t depend on this anyway …

but - what is to do next ?On Sam, 24 Jun 2000, you wrote:

when i write:
double v3x, v3x, v1x

v3x = v1x + v2x;
and
v1x=-2
v2x=2
then my compiler tells me that v3x = -0 but i think it must be 0
!!??

On what type of computer are you compiling this? The only thing I can
imagine (and I do not know how to control this) happening is your
computer or c-compiler/library using one-complement signed numbers.
That’s the only explanation I can think of that would create both a 0
and -0 number. Unless someone has a better explanation. :slight_smile:

For fun, try: v3x = v2x + v1x, with v1x = -2 and v2x = 2. If that one
comes up with 0 my rambling might be true. :slight_smile:

Regards,

Pieter Hulshoff


From:
Joachim Schiele
[ http://www.dune2.de || Linux - my way! ]

This may have something to do with the way c compilers deal with
statements with statements with floating point and integer values.
Some compilers don’t do these conversions as well as we would
like, so it is usually a better idea to cast integer variables when they
are used in this type of situations and for integers to have a .0
appended to them. This sounds like something that should be
handled by the compiler, but I’ve seen some vague bugs caused
by this.

At 07:30 PM 6/24/00 +0200, you wrote:>with this function i set my Surface and the programm always crashed

because of this:

when i write:
double v3x, v3x, v1x

v3x = v1x + v2x;
and
v1x=-2
v2x=2
then my compiler tells me that v3x = -0 but i think it must be 0
!!??

and my second problem is:
how to check if something like this happens ?

if (v3x = -0) doesn’t work !!!
and a check for (v3x = 0) does the same
damn

if someone can help me - PLEASE DO IT

Thank you


From:
Joachim Schiele
[ http://www.dune2.de || Linux - my way! ]

Joachim Schiele wrote in message
news:00062502501007.02224 at game.dune2.de…> On Sam, 24 Jun 2000, you wrote:

when i write:
double v3x, v3x, v1x

v3x = v1x + v2x;
and
v1x=-2
v2x=2
then my compiler tells me that v3x = -0 but i think it must be 0
!!??

Most floating point systems have a positive and a negative zero.
Appearantly you got the latter because your first operand was negative. The
lesson here: floating points are messy. Avoid where possible.


Rainer Deyke (root at rainerdeyke.com)
Shareware action/role-playing games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor