PDA

View Full Version : still thinks this looks weird


KhalidTheMighty
12-17-2003, 06:00 AM
ok... this is the second time this happend to me... not that i didnt win the fight... i just want to know, why does it show this:

You have encountered King Agrippa which lunges at you with Flaming Wingnuts!

Level: 13
Start of round:
King Agrippa's Hitpoints: 27.6
YOUR Hitpoints: 103
Your hellhound fights with you, but sometimes gets in the way.
Your hellhound bites King Agrippa for 2 damage!
Your hellhound bites King Agrippa for 2 damage!
Your hellhound bites King Agrippa for 2 damage!
Your hellhound bites King Agrippa for 2 damage!
You hit King Agrippa for 14 points of damage!
Your hellhound tries to bite King Agrippa but MISSES!
Your lover inspires you to keep safe!
King Agrippa hits you for 7 points of damage!
Your hellhound bites King Agrippa for 5.6 damage!
End of Round:
King Agrippa's Hitpoints: 8.8817841970013E-16 <------- ???
YOUR Hitpoints: 96

MightyE
12-17-2003, 11:14 AM
Thanks Khalid, I fixed this, the end of the round we round the creature's health so that very tiny fractions of a hitpoint shouldn't cause a problem :-) Please let me know if the issue continues.

KhalidTheMighty
12-17-2003, 04:57 PM
no problem

ive noticed it with another creature too, its longer time ago though

Decaying Skeleton's Hitpoints: 6.66133814775E-16

MightyE
12-18-2003, 09:30 AM
Yeah, it's the result of floating point rounding errors. Since computers have a finite precision when dealing with decimal numbers, and since that precision is intended to be very many digits in a lot of cases, they will round off digits that are a lot of places out, and if reasonable, simply display the closest whole number when there would be a lot of zero's. The E notation (scientific notation) there means "times ten to the" so your number:
8.8817841970013E-16
means 8.8817841970013 times ten to the -16, or
0.00000000000000088817841970013

Operations on decimal numbers are known as "floating point operations" and at least on Intel x86 architectures (we're AMD, but it's the same architecture), there's a rounding error very far out, and the result is that a floating point representation of 0 (zero) is rarely exactly zero. To that effect, there's a quote:
10.0 divided by 10.0 rarely equals 1.0
what this means is that if you do the following in code:
if (10.0 / 10.0 == 1.0) {
//put code that you don't want to execute here.
}
you'll very rarely succeed that test condition. For this reason, when dealing with floating point numbers, and needing to test equality, you often have to round. Testing if 8.8817841970013E-16 is greater than 0 (zero), you'll find that it *is* greater than zero.

For our purposes, we don't permit creatures to possess partial hitpoints at the end of a round, and so we can round to the closest whole number, and test the result.

Sneakabout
12-18-2003, 10:46 AM
I think that that explained more about how computers work than I wanted to know - I'm a bit worried about them now.

Moonchilde
12-18-2003, 01:45 PM
I think that that explained more about how computers work than I wanted to know - I'm a bit worried about them now.

Good you should be :) Especially when people want to remove ballot trails from things like voting or anything else which is vitally important and which is controlled by compturs :)

[and no, that's not really a political rant though it could be taken as one, so don't go off on that tangent]

Sneakabout
12-18-2003, 02:46 PM
::reads Slashdot and knows all about Diebold.

Thank goodness we still have paper votes in the UK. Doesn't mean I'm going to vote, but still...