🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Float division

Started by
8 comments, last by WitchLord 15 years, 3 months ago
Hello, I've got following code: float factor = 0.5f; int t = float(timeout) / factor; // timeout is integer value And it gives me division by zero error. Am I doing something wrong, or is this a bug?
Advertisement
You're not doing anything wrong. This has got to be a bug.

I'll investigate this. Thanks.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I can't reproduce this error. I tested with both 2.15.2 and the latest WIP.

Can you send me a test that reproduces the bug?

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Hello,

Version 2.16.0, and still the same:

float t = 1.0f / 0.5f;

Gives compile-time division by zero... It just looks like float literals are casted to integers during compilation...

[Edited by - scypior on April 4, 2009 5:44:10 PM]
I can also confirm that neither are reproducible for me on 2.16.0 running Linux.
This may have to do with your locale settings. Is your OS configured to use comma as the floating point decimal character?

I'll make some tests on this.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Yes, and changing OS settings to '.' helps. Damned comma floats! ;)
Ah, at least we have confirmed the cause.

Obviously the compiler cannot be affected by this locale, so I'll have to find a way to turn off international settings while compiling (or perhaps write my own string to float converter).

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Try adding:
setlocale(LC_ALL, "C");

to your program somewhere before you create the script engine. Does that help?
I just checked in a fix for this. I simply added a call to setlocale(LC_NUMERIC,"C") before calling strtod in the compiler. Afterwards I restore the original local so the rest of the application isn't affected.




AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement