Andrew Channels Dexter Pinion

Wednesday, October 17, 2001

Problem solved, well kind of. After some testing I concluded that the problem was caused by the different results I was getting when rounding positive and negative numbers in the two languages. The original Python code gives the same results as the Javascript code but only for positive numbers. This was something I only found out as we approached the meridian (when the Sun crosses the equator) and the application started to use negative latitudes. I scratched my head, I pondered, I even read a few manual entries, but eventually I managed to hack together a solution; >>> if lat < 0: >>>      lat = (round(int(lat/2) - 1) * 2) + 1 >>> else: >>>      lat = (round(lat/2 - 1) * 2) + 1 >>> It may not be pretty, but it works. As the purpose of the exercise is to produce the same results in Python as in Javascript I think it is a valid solution. I started looking at math.floor and associated functions but concluded that the underlying operations in the maths libraries of the two languages are just incompatible and I would have to settle for this. My next challenge is to integrate support for comma delimited files and gadfly in the dbBrowser sample application for PythonCard. As usual any and all suggestions are welcome.
posted by Andy Todd 5:39 PM

Friday, October 05, 2001

Today's technical problem involves rounding floating point numbers in different programming languages. I've converted some code from Javascript to Python and am getting inconsistent results. The original Javascript is; var lat = delta * (360/TWOPI); // lat is munged about and eventually contains -3.0 lat = (Math.round(lat/2 - 1) * 2) + 1; WScript.echo(lat) // outputs '-3' And my Python version is; >>> lat = -3.0 >>> latty = (round((lat/2) - 1) * 2) + 1 >>> latty -5.0 So we have a rounding issue. Any suggestions? Anyone?
posted by Andy Todd 4:13 PM