Yahoo Clever wird am 4. Mai 2021 (Eastern Time, Zeitzone US-Ostküste) eingestellt. Ab dem 20. April 2021 (Eastern Time) ist die Website von Yahoo Clever nur noch im reinen Lesemodus verfügbar. Andere Yahoo Produkte oder Dienste oder Ihr Yahoo Account sind von diesen Änderungen nicht betroffen. Auf dieser Hilfeseite finden Sie weitere Informationen zur Einstellung von Yahoo Clever und dazu, wie Sie Ihre Daten herunterladen.
Question about Java's double variable type!?
Every website says that a double can store values up to "±439E-324 to
±1.7976931348623157E+308"
Does that mean that they can store up to 1.7976931348623157 with the decimal point moving to the right 308 places? If so that must be a big number. Does that mean a double is bigger than a long? Thanks.
3 Antworten
- nonlinearLv 6vor 1 JahrzehntBeste Antwort
Yes, a Double can be a larger and smaller number than even a long int. You are comparing Double and Long but it is not a useful comparison you are trying to make. Let me explain.
From the first link below: "Double precision arithmetic has very little speed penalty on modern CPUs. Normally you should use double in preference to float. It gives you 14 to 15 significant digits where float gives only 6 to 7. The only advantage to float is compactness. In comparison, a typical scientific pocket calculator will give you 10 significant digits, and will automatically round for display."
The key here is that double is giving you 14-15 significant digits so you can do a very large or very small number but at a cast of speed. Read the link below and you will also find out that chips do not handle doubles the same way you handle fractions and that is important when you are processing mathematical things. For example, you should never do an if( x == 1.0024) as this will almost always fail because x could be 1.0024000001. (remember you get 14-15 digits of precision.
Integer operators (which operate only on integers) are very fast in comparison and are used when partial numbers are not used and do not make sense (counting, looping, pennies, offsets, memory addresses, string length, etc.) but their limit is that you do have a high and low value to worry about.
I hope this helps.
- vor 1 Jahrzehnt
The thing to remember with the double variable type is that it stores floating point numbers. Doubles work by splitting the number into a mantissa (fraction part) and an exponent. This contrasts against the long integer which holds the number in a binary format.
What this all means is that a double can hold a larger range of numbers in the same amount of space but it does so at a lower degree of precision.
Both the long and double variable types are 8 bytes (64 bits) in Java.