Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
If somebody thinks that floats are easy...
Then yes they are easy like 0.1+0.1+0.5+0.3 == 1 right? -
Floats are not that difficult. You just don't compare for equality, EVER. Instead, you use <, >, or test for an interval.
On the other hand, you can often get away with integer arithmetics in proper resolution, like basing all math on tenths or hundreds of a cent in currency arithmetics. -
I have a floatEq function that I use everywhere
abs(a-b} < 10 * FLOAT_MIN
Since float_min is a negligible value in most situations, for the rest you reimplement it with defined behavior anyway. -
Pickman6526y@Lor-inc careful. The error spreads and it could fail if before using that you perform several operations that introduce new error.
-
Pickman6526y@Gregozor2121 sadly floating point arithmetics is part of your job. Learn to deal with it, you won't always be able to work around it. It's not trivial but it's not one of the most difficult topics anyway.
-
@Pickman If I encounter problems like that, I increase the tolerance. Rounding errors of any kind follow normal distribution so at 40*FLOAT_MIN it's safe to assume that the error will never cross it.
-
@Lor-inc Complex numerics can be pretty difficult to get right because you also have to look at your problem domain, e.g. badly conditioned things. But once you get into that rabbit hole, you'd use existing numerics software anyway instead of writing it yourself.
-
You may not like memory management but you definitely should learn learn it and embrace it these people who run around using JRE, and .NET and the just “code to a SDK” because pointers, allocating and deallocating “is scary” ...nooooo once you truly understand it you’ll understand the power and never use a garbage collector again. I use to be java and C# developer then I learned C, assembler and C++ never will I return to the “utopia lie” of run time environments
-
Pickman6526y@Lor-inc you should really try a different approach. Numeric instability is a thing and can lead to rather severe changes, I'm speaking the order of 10e01 after just a few bad operations. In short there's no catch-all solution but as long as you know what is happening you will be fine. Essentially don't put that approach in a library XD
Related Rants
-
nickj15Why did the integer drown? Because it wouldn't float.
-
nanoandrew446!rant *walks into university library* *sits down at a computer 😶* *looks around to see if anyone is look...
-
Fenix14DO YOU FUCKING SERIOUSLY TELL US IN THE SECOND SEMESTER OF OUR MASTERS DEGREE THAT WE SHOULD BE CAREFUL THAT A...
Me talking to my prof about the app that i have to make to pass the oop course early.
Prof> So can you add some kind of a random algorithm to that? You can use float for tha....
Me> NOOOOOOOO
Prof> ...
Me> ...
Me> I wont use floats, i will recreate fractions if i have to.
Prof> Why? There must be a way to compare floats easly...
Me> Nope. If you hate somebody, make them do somthing using floats. I will do that my way.
Prof> okay...
I nearly got myself in bigger shit that im now. I still have to make the app in C++ (Big OOF) but at least i wont have to dick around float arythmetric.
I wish i could do it in C#... I dont like that memory managment...
rant
university
float