ZScript's single-precision float type should be dealt with

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
phantombeta
Posts: 2088
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

ZScript's single-precision float type should be dealt with

Post by phantombeta »

Basically, the 32-bit floating-point type is janky as hell. It barely works - the VM can't actually do single-precision FP arithmetic, so the only purpose of it is to export a few classes from the C++ side and introduce some nasty glitches (specially in MP) due to FP round-off issues.
There's really two ways to solve this - either implement it properly, or change the few places where it's needed to be double-precision instead and turn "float" into an alias for "double".

This isn't really the best place to put this, but I have no idea where else it could go - it's not a feature suggestion, and it's not a bug report.
User avatar
Major Cooke
Posts: 8175
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: ZScript's single-precision float type should be dealt wi

Post by Major Cooke »

I agree. It kinda gives the wrong impression too, which is just convoluted as all hell.

It's just a shame that it was introduced as a 'float' in DECORATE.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49067
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript's single-precision float type should be dealt wi

Post by Graf Zahl »

The only purpose of it is to define structs or arrays with it. The last time I proposed removing the shorter types (int 8, int 16, float32) there was some vocal opposition that this would be detrimental to their space saving efforts.

Also, what's the problems? All internal math is done as doubles, when a single precision float is read it is immediately converted to a double, only when written back it is as a float again. so it's hard to see how this can cause desyncs. The code should be the same for everyone so the round-off glitches should also be the same, unless some compilers screw this up.

That said, I have no problem removing all support for this type except for declaring native class members, and I think I can also remove the small number that still exist.
User avatar
phantombeta
Posts: 2088
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: ZScript's single-precision float type should be dealt wi

Post by phantombeta »

Graf Zahl wrote:Also, what's the problems? All internal math is done as doubles, when a single precision float is read it is immediately converted to a double, only when written back it is as a float again. so it's hard to see how this can cause desyncs. The code should be the same for everyone so the round-off glitches should also be the same, unless some compilers screw this up.
Basically, not all processors do floating-point arithmetic in the exact same way, due to differences in how they're designed. While this is fine for most cases, this is horrible for things that need to be perfectly synchronized to work - the amount of FP error will be very slightly different, and it will also slowly build up. With client/server, this probably wouldn't matter too much, but I'm fairly sure it does matter a lot with P2P.
This is specially true between different architectures.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49067
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript's single-precision float type should be dealt wi

Post by Graf Zahl »

Any IEEE conformant FP unit should do single<->double precision conversions the same. Is this just some theoretical concern or do you have something verifiable where errors accumulate?
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: ZScript's single-precision float type should be dealt wi

Post by _mental_ »

Actually, most of game engines stick to single-precision floating point numbers only. And they somehow work.
For example, take a look at a quite popular commercial physics middleware. It uses just floats while depending on use case it can be affected by their imprecision.
In other words, particular bugs caused by FPs should be reported and fixed. Some generic concerns won’t fly here, sorry.
Post Reply

Return to “Scripting”