Andrew Channels Dexter Pinion

Wherein I write some stuff that you may like to read. Or not, its up to you really.

October 17, 2001

Python vs Javascript Continued

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 at October 17, 2001 05:39 PM