View Issue Details

IDProjectCategoryView StatusLast Update
0000780LDMud 3.6Generalpublic2022-01-09 20:31
Reportersinnvoll Assigned ToGnomi  
PrioritynormalSeveritytweakReproducibilityalways
Status resolvedResolutionfixed 
Fixed in Version3.6.5 
Summary0000780: Seltsame float 0,
Descriptionzlpc return 0.; Got=0
zlpc return !0.; Got=0
zlpc return 0.==0 Got=1
TagsNo tags attached.

Activities

zesstra

2011-02-19 22:28

administrator   ~0002004

Ok, concerning example 1:
zlpc in UNItopia uses to_string() for output of floats. to_string() uses "%g" in sprintf() to print T_FLOAT. And the sprintf manpage states: "a decimal point appears only if it is followed by at least one digit."
I think, we have to include that comment as well in our manpage of to_string - or change it in a way to print the same as our sprintf("%d")...

Note: Our %d in sprintf does not behave the same: 0.0 is printed as "0.0".

Example 2:
Basically, 0.0 is not equal 0, so !0. == 0 is in general justified. It just looks contradictory to Example 3.

Example 3:
The F_EQ (==) operator converts T_NUMBER into double before comparing them with == with the T_FLOAT argument, therefore the comparison returns true...

zesstra

2011-02-19 22:56

administrator   ~0002005

Sin suggested to document the special meaning of 0 (e.g. assignable to every type, initialization value for any type, but despite this always an integer) and its implications.

Gnomi

2011-02-21 23:10

manager   ~0002022

Hmm, I think example 2 should return 1. !x should be the same as x == 0.

Gnomi

2021-04-16 22:07

manager   ~0002614

Although we don't like the current behavior, we hesitate to change it, because one cannot detect where it will break existing code.
Therefore we decided to issue warnings, whenever floating point numbers are used in a boolean context and pragma warn_deprecated is in effect.

Issue History

Date Modified Username Field Change
2011-02-19 21:51 sinnvoll New Issue
2011-02-19 22:28 zesstra Note Added: 0002004
2011-02-19 22:56 zesstra Note Added: 0002005
2011-02-21 23:10 Gnomi Note Added: 0002022
2021-04-16 19:48 zesstra Project LDMud 3.5 => LDMud 3.6
2021-04-16 19:48 zesstra Category LPC Language => General
2021-04-16 22:07 Gnomi Note Added: 0002614
2021-06-04 09:28 Gnomi Assigned To => Gnomi
2021-06-04 09:28 Gnomi Status new => assigned
2022-01-09 20:31 Gnomi Status assigned => resolved
2022-01-09 20:31 Gnomi Resolution open => fixed
2022-01-09 20:31 Gnomi Fixed in Version => 3.6.5