• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

limiting value?

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



when u run the code, from the 16 loop onwards, number takes a constant value. why is that? using long a limiting value is also reached. why is that? is it only a DOS thing? if u make a GUI window and display number in that will it go on displaying the numbers?

Ali
 
author and iconoclast
Posts: 24203
44
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
The largest value an int can represent is 2^31-1; the largest value a long can represent is 2^63-1. They are stored in a finite number of machine bits, so there's a finite magnitude they can represent.

The float and double data types have much larger ranges, but lower precision.
 
Ali Gilani
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so if i want to view beyond the limits??


and what do u mean by lower precision? if the value is 2343443545 will double show it as 2343443545.0 or 2.3e9?


Ali
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
44
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
Before we get into this: note that none of this is unique to Java. Many computer languages -- especially those related to FORTRAN and C -- behave this way.

Integers "wrap around". If you add one to the largest possible integer, you don't get what you expect. This is called "overflow". If you add one to the largest positive int in Java, you actually get the largest possible negative int -- i.e., (2^31-1) + 1 -> -2^31 . This is a result of something called "two's complement" notation -- the way that negative numbers are represented.

ints and longs are exact, while floating-point numbers (float and double) are not. Remember that between any two real numbers, there are an infinity of intermediate values. As a result, no finite computer representation can represent an arbitrary real number exactly. The "exactness" of a floating-point representation is called its precision. floats have 20-something bits of precision, and doubles have 50-something. Because a long is 64 bits, that means that there isn't a unique double value for each possible long value -- i.e., some adjacent long values correspond to the same double value.

Here's an overview article at Wikipedia which explains all of these concepts.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic