Improved code.  Previous version went against the POSIX convention.

# Following the POSIX convention,
# halfway cases are rounded away from zero,
# to the extent this is possible given the inherent
# inexactitude of the floating-point representation.
round = func(arg, quantum=1){
   if (quantum == 0) {
     return arg;
   }
   if (quantum < 0) {
     quantum = -quantum;
   }
   sign = 1;
   if (arg < 0) {
     arg = -arg;
     sign = -sign;
   }
   return sign * quantum * int(0.5 + arg/quantum);
}

print(0.5, " -> ", round(0.5), " should be 1");
print(-0.5, " -> ", round(-0.5), " should be -1");
print(120.37, " -> ", round(120.37, 0.025), " should be 120.375");

Result:

0.5 -> 1 should be 1
-0.5 -> -1 should be -1
120.3699999999999 -> 120.375 should be 120.375

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to