From: Panayotis K. <pan...@pa...> - 2010-11-08 10:13:38
|
Hello all! I am implementing CoreLocation library (actually it is ready and working) but I'd like your opinion about one thing. Here http://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocation_Class/CLLocation/CLLocation.html#//apple_ref/doc/uid/TP40007126-CH3-SW27 is a list of constant double values. These values define the accuracy of the location, and I found that they have meaningful values (i.e kCLLocationAccuracyNearestTenMeters is 10, kCLLocationAccuracyKilometer is 1000 etc). I have created a class containing these static values, but since these are double values and not integers, it is always possible that equality might not work as expected. I tried to check every one of them with something like java_value == kCLLocationAccuracy_value and they all seem OK. On the other hand, it might be possible to create a wrapper method that returns this value, i.e. something like public static double Kilometer () { .. } in java and + (double) Kilometer__ { return kCLLocationAccuracyKilometer; } in obj-c, and use the static methods instead. This might be safer but it is slower. Since the "constant variable" solution works fine, I'd rather prefer that solution. What do you think? |
From: Paul P. <bay...@gm...> - 2010-11-08 16:12:06
|
Checking equality on double or float values is always fishy. Unfortunately BigDecimal hasn't yet become a priority, but that would be a much safer implementation. It doesn't lose precision, making it a good candidate for sensitive numbers, such as currency calculations. If you do go down that route though, make sure to use "compareTo" and not "equals". E.g. "5.40" does not "equals" "5.4", but "compareTo" will return 0. Forgive me if I am stating anything you already know. Paul Poley On Mon, Nov 8, 2010 at 4:13 AM, Panayotis Katsaloulis < pan...@pa...> wrote: > Hello all! > > I am implementing CoreLocation library (actually it is ready and working) > but I'd like your opinion about one thing. > > Here > > http://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocation_Class/CLLocation/CLLocation.html#//apple_ref/doc/uid/TP40007126-CH3-SW27 > > is a list of constant double values. These values define the accuracy of > the location, and I found that they have meaningful values (i.e > kCLLocationAccuracyNearestTenMeters is 10, kCLLocationAccuracyKilometer is > 1000 etc). > > I have created a class containing these static values, but since these are > double values and not integers, it is always possible that equality might > not work as expected. > > I tried to check every one of them with something like > java_value == kCLLocationAccuracy_value > and they all seem OK. > > > > > On the other hand, it might be possible to create a wrapper method that > returns this value, i.e. something like > > public static double Kilometer () { .. } > > in java and > > + (double) Kilometer__ { return kCLLocationAccuracyKilometer; } > > in obj-c, and use the static methods instead. > This might be safer but it is slower. > > Since the "constant variable" solution works fine, I'd rather prefer that > solution. > What do you think? > > > > ------------------------------------------------------------------------------ > The Next 800 Companies to Lead America's Growth: New Video Whitepaper > David G. Thomson, author of the best-selling book "Blueprint to a > Billion" shares his insights and actions to help propel your > business during the next growth cycle. Listen Now! > http://p.sf.net/sfu/SAP-dev2dev > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users > |
From: Panayotis K. <pan...@pa...> - 2010-11-08 16:38:20
|
On Nov 8, 2010, at 6:11 PM, Paul Poley wrote: > Checking equality on double or float values is always fishy. Unfortunately BigDecimal hasn't yet become a priority, but that would be a much safer implementation. It doesn't lose precision, making it a good candidate for sensitive numbers, such as currency calculations. > > If you do go down that route though, make sure to use "compareTo" and not "equals". E.g. "5.40" does not "equals" "5.4", but "compareTo" will return 0. Forgive me if I am stating anything you already know. > > Paul Poley The problem unfortunately is under Obj-C code and not Java. :) I agree with you, but right now, after doing some tests, I have the feeling that actually these values are used by iOS SDK more as a reference (and is checked for being larger/smaller than the specified value) and not really for equality. Thus I believe that it will be safe to use double values, for now. |
From: Arno P. <ar...@pu...> - 2010-11-08 19:28:10
|
I'm assuming that the location-API in iOS is already using double. In that case we should also just offer doubles in the Java-API. The programmer needs to know about the consequences of using double; both in Java and in Objective-C. Arno On 11/8/10 8:38 AM, Panayotis Katsaloulis wrote: > > On Nov 8, 2010, at 6:11 PM, Paul Poley wrote: > >> Checking equality on double or float values is always fishy. Unfortunately BigDecimal hasn't yet become a priority, but that would be a much safer implementation. It doesn't lose precision, making it a good candidate for sensitive numbers, such as currency calculations. >> >> If you do go down that route though, make sure to use "compareTo" and not "equals". E.g. "5.40" does not "equals" "5.4", but "compareTo" will return 0. Forgive me if I am stating anything you already know. >> >> Paul Poley > > > The problem unfortunately is under Obj-C code and not Java. > :) > > I agree with you, but right now, after doing some tests, I have the feeling that actually these values are used by iOS SDK more as a reference (and is checked for being larger/smaller than the specified value) and not really for equality. > Thus I believe that it will be safe to use double values, for now. > ------------------------------------------------------------------------------ > The Next 800 Companies to Lead America's Growth: New Video Whitepaper > David G. Thomson, author of the best-selling book "Blueprint to a > Billion" shares his insights and actions to help propel your > business during the next growth cycle. Listen Now! > http://p.sf.net/sfu/SAP-dev2dev > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users |