Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can method return two values?  RSS feed

 
Ed Dablin
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
Ashish R Garg
Greenhorn
Posts: 8
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • 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.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Clapham
Sheriff
Posts: 22503
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!