• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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: 43028
76
  • 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: 67671
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: 27371
88
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.
 
Blood pressure normal? What do I change to get "magnificent"? Maybe this tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic