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
Search - "rounding"
-
In a programming contest, I forgot how to round numbers in Java, an I needed a 3 number rounding, so I multiplied the number by 1000, then sum 0.5 and convert it to integer so the decimal part would be gone, finally, just print the number except the 3 last digits as a string, put a period and print the other 3 digits.
I must say I'm not proud of that.5 -
So I once had a job as a C# developer at a company that rewrote its legacy software in .Net after years of running VB3 code - the project had originally started in 1994 and ran on Windows 3.11.
As one of the only two guys in the team that actually knew VB I was eventually put in charge of bug for bug compatibility. Since our software did some financial estimations that were impossible to do without it (because they were not well defined), our clients didn't much care if the results were slightly wrong, as long as they were exactly compatible with the previous version - compatibility proved the results were correct.
This job mostly consisted of finding rounding errors caused by the old VB3 code, but that's not what I'm here to talk about today.
One day, after dealing with many smaller functions, I felt I was ready to finally tackle the most complicated function in our code. This was a beast of a function, called Calc, which was called from everywhere in the code, did a whole bunch of calculations, and returned a single number. It consisted of 500 or so lines of spaghetti.
This function had a very peculiar structure:
Function Calc(...)
...
If SomeVariable Then
...
If Not SomeVariable Then
...
(the most important bit of calculation happened here)
...
End If
...
End If
...
End Function
But for some reason it actually worked. For days I tried to find out what's going on, where the SomeVariable was being changed or how the nesting indentation was actually wrong and didn't match the source, but to no avail. Eventually, though, after many days, I did find the answer.
SomeVariable = 1
Somehow, the makers of VB3 though it would be a good idea for Not X to be calculated as (-1 - X). So if a variable was not a boolean (-1 for True, 0 for False), both X and Not X could be truthy, non-zero values.
And kids these days complain about JavaScript's handling of ==...7 -
$number = 3000/365*365-3000
echo $number
Output:
4,54747350886E-13
No, Just No. I really like you PHP but thats supposed to be zero. I don't got time for your Tantrum's. I got work to do!
PS: Does anyone know why this happens? Solved it by rounding on 10 decimals but prefer it would just answer 0 instead of me having to force it back.23 -
Microsoft, you can't sneak this past me! I notice you're putting rounded corners in specific parts of your OS, and I don't like it. It's inconsistent with your design and your slow roll-out of the rounding makes things round in some areas (such as the context menu in the calculator app) and square in other areas! (such as the context menu anywhere else)
All I'm saying is either do it everywhere, or do it nowhere.
(I realize the terminal is not an official application YET, but it's a good example)8 -
What grinds my gears:
IEEE-754
This, to me, seems retarded.
Take the value 0.931 for example.
Its represented in binary as
00111111011011100101011000000100
See those last three bits? Well, it causes it to
come out in decimal like so:
0.93099999~
Which because bankers rounding is nowstandard, that actually works out to 0.930, because with bankers rounding, we round to the nearest even number? Makes sense? No. Anyone asked for it? No (well maybe the banks). Was it even necessary? Fuck no. But did we get it anyway?
Yes.
And worse, thats not even the most accurate way to represent
our value of 0.931 owing to how fucked up rounding now is becaue everything has to be pure shit these days.
A better representation would be
00111101101111101010101100110111 <- good
00111111011011100101011000000100 < - shit
The new representation works out to
0.093100004
or 0.093100003898143768310546875 when represented internally.
Whats this mean? Because of rounding you don't lose accuracy anymore.
Am I mistaken, or is IEEE-754 shit?4 -
Stop rounding the corners of content!!!!! Round corners are meant for buttons!!!! Not my fucking video!!!!11
-
The new Gmail shows how redesign should not be done. Everywhere white, bright colors, no contrasts. Here rounding is smaller, there bigger, there is shadow, here not. Seriously, what I saw a few months ago at the announcements looked much better than what I see now. It's good that I'm using a desktop client, because I think I'd switch completely to Outlook.8
-
This.
Not the worst but almost all of us (including me) handle strings like fucking morons.
If the input doesn't need to be an exact match we use a explicit comparison operator, when the input should explicitly match we do a loose comparison operator.
I'll format the crap out of a number, convert it, validate decimal places, check for float rounding hell, give it a absolute value and return it correctly formatted for the users locale but half the time I forget to trim their input. 🤦♂
Like I said - just a tad fucking moronic isn't it?3 -
Spent 2+ months this year building two new software courses. They've netted me a total of... $17.00
That's 5 cents per hour at 40/hours a week, not bad!!!!
also please fucking tell me how a $49.99 course with 92 enrollments this month earns me a grand total of $93 (even rounding up here for generosity)
creator: $93
udemy: $4506
udemy: "instructor gets 37% of comissions"
yeah okay then where is my fucking $1000+
I mean what in the literal FUCK is going on here
better put: i average a single fucking dollar for each $50 course I sell?
Please kill me and end it all in this mindless race to the bottom
taking a deep dive on this revenue share and then i'm going to fucking get the money i deserve10 -
We bring you messages from the future...
Is Apple rounding up timestamps, or have they started using Scala Futures? 😂😂3 -
Some days I feel like I really know what I am doing and today was not one of these days...
Working on a game engine using Vala and now using Raylib in the backend for rendering and input.
Wrote a VAPI for Raylib and when I was doing the 'Rectangle' struct... I made it's members integers when they are floats...
So this whole time; when using a camera everything would jitter like crazy.... because I was taking the transform which is all floats... rounding it then casting to an int only for the int to be cast into a float again....
Lo and behold; changing the members to floats and removing the rounding and casting makes everything silky smooth...
I have been debugging every bit of my current render loop trying to work this out when it was 100% unrelated.... I hate myself sometimes1 -
Code reviewing, came across this:
Double val = item.getPrice() * pointMultiplier;
String[] s = String.split(val.toString(), "\\.");
points = Integer.parseInt(s[0]);
if(Integer.parseInt(s[1]) > 0) { points++; }
Usually I'd leave it at that, but to add insult to injury this was a level 3 developer who had been there for four (4!!!!) years.
She argued with me that we shouldn't round up loyalty points if theres only 0.00001 in the calculation.
I argued that since it's a BigDecimal, we can set the rounding factor of it.
She didn't understand that solution, refused to hear it.
The code is probably still there.5 -
))| THE BEST AND WORST WAY|((
))| TO DELETE A LINE IN BASH |((
(Think you can do better? Vote
now on your phones!)
WORST: Hold backspace until satisfied
BEST: Using a pen or other pointing device capable of causing semi or permanent damage to your screen, count how many characters the line in question consists of. Write this down on a piece of paper (after all, your terminal is occupied) and using long division, or any other means, divide this number by two, rounding as you please. Press the "right arrow" key as many times as necessary to reach the end of the line. This might be 0 - if so, congratulations, you may skip this step! Once complete, refer to your piece of paper, and taking your newly calculated number, press the "left arrow" key exactly that many times. If you have a short attention span or are worried you will lose count, take a tally or use some other primitive count recording method. Once the key has been pressed the correct number of times, hold down either control key on your keyboard and take a deep breath - there's no going back now (!) - press the "k" key (you should still be holding a control key!) and take a sigh of relief. You're halfway there! If you need a break, take one. When you're ready to finish the task, hold a control key again and take another deep breath. When you are ready to complete the task (don't hold your breath too long!) press the "w" key. Congratulations!! Your line has been deleted!! Some may call you a fucking idiot for not just pressing ctrl-w at the start, but don't listen to those people! They probably delete stuff by accident all the time! Now, take a lie down, and give a moment's silence for the poor poor line you just brutally dissected and murdered.
Think you can do better? Vote now on your phones!9 -
Just had a class where we had to write a heap adding algorithm in Java to reduce rounding error for x amount of floats being added together
After an hour of writing code with no testing anything I finished. Ran the JUnit tests provided by the teacher and it passed all the tests!
Who says it can't work the first time?2 -
can we just get rid of floating points? or at least make it quite clear that they are almost certainly not to be used.
yes, they have some interesting properties that make them good for special tasks like raytracing and very special forms of math. but for most stuff, storing as much smaller increments and dividing at the end (ie. don't store money as 23.45. store as 2,345. the math is the same. implement display logic when showing it.) works for almost all tasks.
floating point math is broken! and most people who really, truely actually need it can explain why, which bits do what, and how to avoid rounding errors or why they are not significant to their task.
or better yet can we design a standard complex number system to handle repeating divisions and then it won't be an issue?
footnote: (I may not be perfectly accurate here. please correct if you know more)
much like 1/3 (0.3333333...) in base 10 repeats forever, that happens with 0.1 in base 2 because of how floats store things.
this, among other reasons, is why 0.1+0.2 returns 0.300000046 -
Dividing currency values across new invoices results in ball aching rounding issues.
Finally solved it and there's no one around to high five.3 -
Today my boss sent me something that smelled fishy to me. While he was trying to simulate Excel's rounding he faced what was to him unexpected behaviour and he claimed that one constructor of the BigDecimal class was "wrong".
It took me a moment why this was happening to him and I identified two issues in his code.
I found one fo the issues funny and I would like to present you a challenge. Can you find a number that disproves his claim?
It's Java if anyone was wondering.
double d = 102.15250;
BigDecimal db = new BigDecimal(d)
.setScale(3, BigDecimal.ROUND_HALF_EVEN);
BigDecimal db2 = new BigDecimal(String.format("%f",d))
.setScale(3, BigDecimal.ROUND_HALF_EVEN);
BigDecimal db3 = BigDecimal.valueOf(d)
.setScale(3, BigDecimal.ROUND_HALF_EVEN);
System.out.println(db); // WRONG! 102.153
System.out.println(db2); // RIGHT! 102.152
System.out.println(db3); // RIGHT! 102.152
P.s. of course the code itself is just a simple check, it's not how he usually writes code.
P.p.s. it's all about the numerical representation types.8 -
Anyone ever tried to fuck around with dynamic programming in machine learning?
My question is more towards rounding numbers.
Any papers on the impact of learning rate or precision that you guys know of? -
How hard is it for people to understand that rounding individual decimal numbers and adding them is not equal to adding them all and then rounding off.
FFS1 -
Is there a way to hibernate before updating windows? I have 15 virtual desktops rounding up to 45 desktops via 3 monitors with different setups, it would be a pain having to restore it all manually 😥1
-
Why does BigDecimal have to be so annoying to work with! Trying to trace my brackets from an excel sum over to Java... Got the sum working now greeted with dodgy rounding! Doh!
-
current language vba.
(14 / 24) - (8 / 24) > (6 / 24)
compiled to true. apparently rounding to 8 digits did the trick. quirky was that debug.printing each calculations showed exactly '0.25' for both not giving a hint about some float issue in the first place. ah, and rounding to 4 digits wasn't right either. -
Algolia says:
"So our price widget doesn't allow decimals, you'll have to create a custom widget"
I do it.
"Hey, It's not working and I verified it's applying the filter correctly. I noticed my price is a string in your index, maybe that's incorrect and causing it to not work?"
They say: "Yep, you'll need to run an update to fix that and change all to floats" (charges an arm and a leg for the thousands of index operations needed to update the data type)
I clear the index and send a single one as a test, verifying it's a float by casting it using (float) then var_dumping. It shows "double(3.99)", but when it gets to Algolia, it's 0.
So I contact support.
"Hi, I'm sending across floats like you say but it's receiving it as 0, am I doing something wrong? Here's my code and the result of the var_dump"
They respond: "Looks like you're doing it right, but our log shows us receiving 3.999399593939, maybe check your PHP.ini for "serialize_precision" and make sure it's set to -1"
I check and it's fine, then I realize that var_dump is probably rounding to 2 decimal points so I change my cast to (float) number_format($row['Price'], 2) and wallah...it works.
Now I've wasted days of paying for their service, a ton of charges for indexing operations, and it was such a simple fix.
if they had thrown an error for the infinite decimal, that would have helped, but instead I had to reach out to find out that was the issue.
#Frustrated. -
Fucking rounding I hate you, trying to write sales figures to an accounting system API that is using some kind of fucked up rounding method that will not balance no matter what I do. Agghh1
-
They want me to change a few details in the CSS in a wordpress website. The theme supports some extra CSS. However, it doesn't seem to work without !important.
Turns out there's a line of CSS dumped in the <head> directly that overrides all "extra" CSS... and about 9 <link> instances after that... oh and some random <style> tags after that...
Oh and rounding shouldn't be done with CSS but with some custom button style editor. For each button. Seperately. Because fuck my life.1