No, the local variable doesn't have a default value at all; it will fail to compile if you don't initialise it. As Staphan says, you only get multiplication if you use the * operator. In fact nothing happens without an operator, if you consider the () after a method/constuctor name to be an operator. The language is different from tha language of simple algebra,.peng shan wrote:The default value of f is zero . . . .
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
Campbell Ritchie wrote:Welcome to the Ranch
Please avoid floats, unless some other API requires them; they simply lose you precision as against doubles.
Why would you expect that program to print 0?
On a 64‑bit machine, you might use all 64 bits for floating‑point arithmetic regardless.Damon McNeill wrote:. . . a float takes half the space. . . .
As soon as you start doing arithmetic, your byte will be turned into an int anyway, except when using the compound assignment operators. The short and byte datatypes probably also have no real‑life use. The byte[] datatype, on the other hand, is very useful for sending information across networks.always use int where a byte would do, no?
Campbell Ritchie wrote:
On a 64‑bit machine, you might use all 64 bits for floating‑point arithmetic regardless.Damon McNeill wrote:. . . a float takes half the space. . . .
You will probably have to have millions upon millions of floating‑point numbers in memory all at once before you notice the difference in memory use.
The default is to use double arithmetic; indeed you either need the terminal f or a cast to turn the arithmetic into a float.
It isn't worth the bother only to lose the already limited precision of double arithmetic.As soon as you start doing arithmetic, your byte will be turned into an int anyway, except when using the compound assignment operators. The short and byte datatypes probably also have no real‑life use. The byte[] datatype, on the other hand, is very useful for sending information across networks.always use int where a byte would do, no?
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
Jesse Silverman wrote:I had the discussion with Campbell in another thread some weeks back, and made almost exactly the same points you did.
I don't even know how one goes about doing the GPU-based stuff in Java, the material I worked with was focused on C/C++/Python and FORTRAN only.
There is some vector API work that has made its way into Java 17 for future progress in this direction.
I agree with Campbell's main point that short of dealing with HUGE numbers of data, there is very little to be bought using float type, at least on the CPU-based and FPU-based instructions that I think Java uses for all normal math.
And yes, this is all way, way beyond the scope of Beginning Java.
Cheers!
Is that reason historical, that Java® was inspired by older languages, developed in the days when 8 bits of memory saved really meant something?Damon McNeill wrote:. . . . There is a reason for the different choices of types, after all.
Campbell Ritchie wrote:Is that reason historical, that Java® was inspired by older languages, developed in the days when 8 bits of memory saved really meant something?
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
There are three kinds of actuaries: those who can count, and those who can't.
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
There are three kinds of actuaries: those who can count, and those who can't.
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
What a splendid website! One of the few places, where, more by luck than good management, the greater imprecision of a float hides the errors.Jesse Silverman wrote:. . . https://0.30000000000000004.com/ . . . .
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
A magnificient life is loaded with tough challenges. En garde tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|