Author: cazfi
Date: Wed Nov 11 18:21:11 2015
New Revision: 30540

URL: http://svn.gna.org/viewcvs/freeciv?rev=30540&view=rev
Log:
Silently allow accuracy error of exactly 1.0 units while converting floating 
point numbers to
network protocol. Tell the amount of error in conversion units if the error 
message in the remaining
cases.

Reported by Jacob Nevins <jtn>

See bug #22960

Modified:
    trunk/common/dataio.c

Modified: trunk/common/dataio.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/dataio.c?rev=30540&r1=30539&r2=30540&view=diff
==============================================================================
--- trunk/common/dataio.c       (original)
+++ trunk/common/dataio.c       Wed Nov 11 18:21:11 2015
@@ -398,10 +398,11 @@
 {
   uint32_t v = value * float_factor;
 
-  FIELD_RANGE_TEST(fabsf((float) v / float_factor - value) >= 1.0 / 
float_factor, ,
+  FIELD_RANGE_TEST(fabsf((float) v / float_factor - value) > 1.0 / 
float_factor, ,
                    "Trying to put %f with factor %d in 32 bits; "
-                   "it will result %f at receiving side.",
-                   value, float_factor, (float) v / float_factor);
+                   "it will result %f at receiving side, having error of %f 
units.",
+                   value, float_factor, (float) v / float_factor,
+                   fabsf((float) v / float_factor - value) * float_factor);
 
   dio_put_uint32_raw(dout, v);
 }
@@ -414,10 +415,11 @@
 {
   int32_t v = value * float_factor;
 
-  FIELD_RANGE_TEST(fabsf((float) v / float_factor - value) >= 1.0 / 
float_factor, ,
+  FIELD_RANGE_TEST(fabsf((float) v / float_factor - value) > 1.0 / 
float_factor, ,
                    "Trying to put %f with factor %d in 32 bits; "
-                   "it will result %f at receiving side.",
-                   value, float_factor, (float) v / float_factor);
+                   "it will result %f at receiving side, having error of %f 
units.",
+                   value, float_factor, (float) v / float_factor,
+                   fabsf((float) v / float_factor - value) * float_factor);
 
   dio_put_sint32_raw(dout, v);
 }


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to