Richard Tookey wrote:
Richard Tookey wrote:As a concept I don't find that weird since in the general case a+b could be be greater than 127.
Richard Tookey wrote:It is fundamental to Java that in the addition of byte, char and short they are first promoted to int so that a+b results in an int which cannot be guaranteed to fit into short. Now as I said before one could get the compiler to do a much much more complex analysis of a program (which of course will make it slower to compile) to decide whether or not the result of the addition will fit into the target type but I prefer it not to.
Bora Sabrioglu wrote:yeah, youre right... lets close this thread
Henry Wong wrote:
Bora Sabrioglu wrote:yeah, youre right... lets close this thread
I think (and I am guessing) the issue here is that you are learning the Java language -- and is coming in with expectations from a different programming language. A Java programmer who has been using it for a bit, don't see this as weird. I think it is better to let go of your expectations -- as it is probably better to learn the different languages without trying to relate them to each other.
Henry
Stephan van Hulst wrote:I'm really happy I don't have to work with pointers and goto statements
Campbell Ritchie wrote:Nothing wrong with pointers … at least not until you try arithmetic on them
Henry Wong wrote:I have no issues with C. In fact, I am currently using the language at this very moment -- porting some code that I wrote a few months ago from Linux to Windows. Of course, you can argue that I am currently doing more C pre-processor coding than C coding...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Henry Wong wrote: I am going to argue that the OP probably may not have much commercial experience with C (in large projects).
Quite frankly, goto statements (even in C) are something that you would really need to justify in using. I personally try my best not to use them, because I don't like to be red-flagged in a code review.
Henry Wong wrote:
I have no issues with C. In fact, I am currently using the language at this very moment -- porting some code that I wrote a few months ago from Linux to Windows. Of course, you can argue that I am currently doing more C pre-processor coding than C coding...![]()
Bora Sabrioglu wrote:
Quite frankly, goto statements (even in C) are something that you would really need to justify in using. I personally try my best not to use them, because I don't like to be red-flagged in a code review.
Now I think its time to quote my role model as far as programming is concerned... imho the best and most talented programmer since the invention of computers - Ken Thompson:
"If you need to go somewhere - goto is the best way to get there."
Bora Sabrioglu wrote:
Now I think its time to quote my role model as far as programming is concerned... imho the best and most talented programmer since the invention of computers - Ken Thompson:
"If you need to go somewhere - goto is the best way to get there."
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Campbell Ritchie wrote:Another weird feature: you know that integer literals are never negative?
A hexadecimal numeral consists of the leading ASCII characters 0x or 0X followed by one or more ASCII hexadecimal digits interspersed with underscores, and can represent a positive, zero, or negative integer.
An octal numeral consists of an ASCII digit 0 followed by one or more of the ASCII digits 0 through 7 interspersed with underscores, and can represent a positive, zero, or negative integer.
A binary numeral consists of the leading ASCII characters 0b or 0B followed by one or more of the ASCII digits 0 or 1 interspersed with underscores, and can represent a positive, zero, or negative integer.
Campbell Ritchie wrote:You need to go back to 1966 for a real great: Edsger Dijkstra; “go to statement considered harmful”.
Campbell Ritchie wrote:Edsger Dijkstra; “go to statement considered harmful”.
"3.8 Goto and Labels
C provides the infinitely-abusable goto statement(...). Formally the goto is never necessary, and in practise it is almost always easy to write code without it.(...)
Nevertheless, there are a few situations where gotos may find a place. The most common is to abandon processing in some deeply nested structure, such as breaking out fo two or more loops at once.(...)
Although we are not dogmatic about the matter, it does seem that goto statements should be used rarely, if at all."
Winston Gutkowski wrote: I don't think it will be very successful in the long run..."
Bora Sabrioglu wrote:
So thats right, makes no sense to have gotos all over the place... but having one or the other goto here and there is just like the spice in the program... having no gotos at all is just so
How can you get more iterations than that? Have you worked out how many iterations that will be and why?Bora Sabrioglu wrote:. . .
Anyone who can make Java make more iterations will get a cow
I could tell the Missus I am just waiting for my loop to finish, then I'll do the washing up
Note:
"Don't try this at home"
Campbell Ritchie wrote:How can you get more iterations than that?
Have you worked out how many iterations that will be and why?
Bora Sabrioglu wrote:
not bad really, this way I learned that a double can have 324 digits after the comma:
Anyone who can make Java make more iterations will get a cow![]()
Henry Wong wrote:BTW, this is an infinite loop. Why? While a double can hold a number with digits 300+ places to the right of the decimal point, it can only hold numbers with a precision of about 15 or 16 significant digits. This means that once the double index variable has a non-zero digit more than 15 or 16 digits from the number that you are adding, you are effectively adding zero (due to rounding). The index will stop increasing in value.
Hence, infinite loop
Bora Sabrioglu wrote:
Have you worked out how many iterations that will be and why?
Since the range of double varies (I guess its JVM or platform dependent) one can't tell for sure how many iterations... but they're enough for you to make one washup or two![]()
Henry Wong wrote:Java's implementation of floating point follows the IEEE 754 standard.
Bora Sabrioglu wrote:
Henry Wong wrote:Java's implementation of floating point follows the IEEE 754 standard.
But only if you use strictfp, right?
Are you sure? I am not convinced. If you look up Double.MIN_VALUE it is 4.9E-324. When you get to such small values, precision is so low (only to the nearest bit, i.e. 0.3010... digits), that 1.0E-324 is < 0.5 × MIN_VALUE. Chances are, the compiler will convert that to 0.0, as the nearest available double, and you will be adding 0 from the very first iteration.Henry Wong wrote: . . . This means that once the double index variable has a non-zero digit more than 15 or 16 digits from the number that you are adding, you are effectively adding zero (due to rounding). . . .
Bora Sabrioglu wrote:"...Nevertheless, there are a few situations where gotos may find a place. The most common is to abandon processing in some deeply nested structure, such as breaking out fo two or more loops at once.(...)"
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
|