Tuesday, May 23, 2006

Bugs in Symbian math library?

This is my experience of using the math library function for Symbian 7.0 (s60 2nd phone, nokia 6600) while writing two applications that require extensive math support in terms of basic function like pow(), acos() along with some advanced functions like lgamma().
The applications (mobimol and mobihf) are currently hosted at my google pages along with their sources at: http://tovganesh.googlepages.com/s60

Simple functions like pow() and acos() seem to have some problem with handling very low values, which are typically less 1.0e-12. So, using such functions with these low value resulted in crashing of the code (in this case the Python interpreter), with no apparent error message. To avert this problem I had to add a wrapper over the pow() or acos() function that reads some what like as follows:


def myacos(ang):
if(round(ang,1)==1.0): return 0.0
return acos(ang)

def mypow(self, x, y):
if (round(y,10)==0.0): return 1.0
if (round(x,10)==0.0): return 0.0
return pow(x, y)


Initially I thought that this problem was only with Python implementation of these method, but it suddenly struck me that the implementation of these function would probably be done by the underlying symbian math library. When I wrote a similar code (for mobihf) in C++ I faced a similar problem of the code crashing with no apparent warnings or errors. To avert this problem I had to write another wrapper in my C++ code, which is probably more correct than the Python version that I had written earlier:


double absd(double x) {
return (x<0.0 ? -x : x);
}

double mpow(double x, double y) {
if (absd(y)<=1.0e-10) return 1.0;
if (absd(x)<=1.0e-10) return 0.0;
return pow(x, y);
}


The most painful part was that abs(y) did not work, and the complier (Symbian SDK on Windows XP for s60 2nd edition) gave me an error indicating that abs() takes an int argument (possibly it took my code to be a pure C code)!! Anyways, I later on discovered that it is better to use fabs() instead.

And finally many math function that are a part of standard C library seem to be not available with the Symbian SDK most notable ones that I missed were: round(), lgamma()

It may be possible that the Symbian OS developers have not paid a lot of attention in writing these specialized functions given the very limited nature of the smartphone platform, but I guess with stiff competition coming up from other quarters (Windows, Linux, SavaJe), it is possibly worthwhile to correct such problem and make the already wonderful Symbian OS more general.

PS. These are solely my private views and have nothing to do with Symbian development team.
Also I have tested these codes only on my Nokia 6600, these may have been corrected in later version of the Symbian OS, consequently I urge the readers to download the code provided in the above link and verify if the "bugs" still persist. If so, please let me know by posting a comment here.

1 comment:

V. Ganesh said...

hey, thanks a lot for the post :)