• 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

Infinity

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The statement System.out.println(100.0 / 0) seems to result in infinity being printed. I am perfectly happy why, but would be interested in any technical explanation...
I would not expect the result of a primitive arithmetic operation to result in a String... Can anyone explain?
Cheers..adam
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Adam,
Welcome to JavaRanch!
The IEEE floating-point standard, which Java follows, allows for a couple of special values: NaN (Not A Number), +Inf and -Inf. They're not strings -- they're just specific bit-patterns within the double and float types. There's no way to represent them as a series of digits, because they're not valid numbers, either. The String representation (NaN or Inf or whatever) is created by whatever method does the printing -- i.e., the println() method calls String.valueOf(double) to produce something that it can render to the screen, and it's this method's job to decide how to render the value; it comes up with the strings "NaN" and "+Inf", etc. If you were to write your own method to format doubles, it could do something else for NaN, whatever you wanted it to do.
 
Adam Smith
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ahhhh. That makes much more sense. Thanks for your help.
reply
    Bookmark Topic Watch Topic
  • New Topic