• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can method return two values?

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've written a method to convert a zip code into two doubles: latitude and longitude. How do I return two doubles?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By returning an object of a class that has two members. Or by returning an array double[2].
 
Ed Dablin
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As some who deals with map data quite a bit, I'd recommend against using doubles. They will cause no end of headaches because of their inaccuracies. Use BigDecimal and your life will be much easier.
 
Greenhorn
Posts: 8
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:As some who deals with map data quite a bit, I'd recommend against using doubles. They will cause no end of headaches because of their inaccuracies. Use BigDecimal and your life will be much easier.



I have also read somewhere about the anomaly with double and float. Is there anything bigger (in size ofcourse) that we can utilize for accuracy?
As I understand, it supports 32 bit unscaled integer value while double supports 64 bit. Please correct me if I am wrong.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ashish R Garg wrote:
I have also read somewhere about the anomaly with double and float.



It's not an anomaly. It's a consequence of the design of the IEEE 754 spec, and of the fact that it's impossible to precisely represent every single one of an uncountable infinity of values with a finite number of digits.

Is there anything bigger (in size ofcourse) that we can utilize for accuracy?



As already mentioned, BigDecimal.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:As some who deals with map data quite a bit, I'd recommend against using doubles.



Although when you're talking about the location of a zip code (as the OP did), then accuracy of doubles isn't really a concern. After all, if you get your latitude accurate to 4 decimal places of a degree, that's the same as to measuring within the nearest 10 metres (if I have the arithmetic right). And accurate to 8 decimal places, that's to within the nearest millimetre. Which would be fine even for engineers building a bridge, I think.
 
reply
    Bookmark Topic Watch Topic
  • New Topic