Actually, there's a whole branch of abstract mathematics dealing with finite precision arithmetics. Also, for those specific values, the function has no errors.
You should look up the principle of charity. My point should be obvious: (int) a could truncate a value very close to what you want to one fewer. From the perspective of reducing bugs, I'd take the original code over yours any day, because it doesn't rely on float arithmetic.
Finite precision does not mean unreliable or random.
You're taking my incredibly specific concern and putting huge generalities in my mouth I didn't say. As I mentioned, (int) a could round down to the wrong angle. The solution in the original post doesn't have that problem.
The magic numbers are strong in this sample as well. I don't know the context, but it might make sense to make getWhateverTheButtonIs() for each of those magical get(int) methods or at least make get work off named constants or an enum.
I'm surprised Java lets you do == between floats... On the other hand, they fucked it up for strings, so, why not fuck it up for floats too?
How did they fuck up == for String? In Java, == always compares addresses for reference types, and if you want a value comparison, you have to use equals. For primitive types, == compares values. For an enum, comparing addresses is fine, because each instance is a singleton. While float equality can be error prone if someone expects infinite precision, it's a necessary feature in any programming language featuring floating point arithmetic.
Hahahaha. Are you sure? Are you absolutely sure? Hint: the answer is in the paragraph you quoted.
Yes, I'm sure. Any two floats with the same bit representation will compare true other than two NaNs. It all makes a lot of sense. The fact that (1/3)*3 == 1 returns false is expected for anyone who has coded in any language using float arithmetic. There is no other way to handle the situation, and armed with an understanding of what a float is, it would be bizarre if it did the "right" thing.
I still don't know what you dislike about String. == compares the identity of two reference variables rather than values in Java. It is confusing for people with no programming experience in a lower-level language, but it makes sense to everyone else.
Makes sense to you, but proves you wrong... come on. You literally wrote that your previous claim was false... why are you still arguing?
At this point, I'm positive you are either trolling or have a strongly held belief about Java that isn't true. Basically, all I've done is ask what your ambiguous statement is in reference to, and you have zero capacity to explain what you mean.
11
u/catithebathtub Mar 20 '22
matrices are heaven
4
u/jwan12 Mar 20 '22
Sadly there isn't an alternative way to make this more readable like switch. Sad Face
2
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Mar 20 '22
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
1
u/funfact15 Mar 20 '22
That
elseat the end could be commented as well.1
u/tedbradly Apr 05 '22
The magic numbers are strong in this sample as well. I don't know the context, but it might make sense to make
getWhateverTheButtonIs()for each of those magicalget(int)methods or at least makegetwork off named constants or anenum.0
u/[deleted] Mar 22 '22
I'm surprised Java lets you do == between floats... On the other hand, they fucked it up for strings, so, why not fuck it up for floats too?