- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
1000000000000000000st
CAPTCHA: abigo - comment written abigoing the rules in the code.
Admin
(coughbignumcough)
Admin
funnily they use a StringBuilder but still use the + for building the string
it would have been easier if they had just done
DecimalFormat df2 = new DecimalFormat("000000");
sb.append(df2.format(ab100000)); sb.append(df2.format(cd100000)); //etc.
Admin
Is he is worried about precision he should be using BigDecimals anyway.
Admin
Not even BigDecimals, this looks like C#, which has had a native base-10 decimal type since day one.
Admin
This is utterly ridiculous. I don't know what that programmer thought he was doing, but he hasn't been writing code to print decimal numbers - he has written highly complicated code that prints floating-point numbers.
Admin
Obviously this code was ported from a Pascal program.
But seriously, don't they know the best way to store a decimal is as a string?
ZING
Admin
Admin
Admin
Admin
When I read gnasher729's comment, there was a line break here:
I thought the comment was suggesting that the code was written in the manner of someone who was high (on drugs). Although the sentence continued, I still think that speculation has merit.
CAPTCHA: minim The minimal portion of "minimal" that you need to convey the concept of "minimal."
Admin
I'm still trying to see any sense in what is finally produced as a string for the file...
Take ab = 1.23, cd = 1.23, e = 1.23
df3.format(Math.floor(d.getAB())) = "1" df2.format((d.getAB() - Math.floor(d.getAB()))*100000) = "-99998" (or is the sign dropped?).
So I get "1-99998" or "199998" for processing ab.
So I would end up with either 1-999981-999981.23 or 1999981999981.23 (when the sign is droppend).
Am I missing something?
Admin
TRWTF is how the preview of this WTF was just as long as the article itself
Admin
It's funny how doubles are good enough to store number in memory, but not in the file. Or maybe all languages have two internal type fdouble and mdouble? Who was hiding this from us? And why?!!!
ingenium indeed
Admin
Watch your parentheses!
d.getAB() - Math.floor(d.getAB()) = 1.23 - 1 = .23 .23 * 100000 = 23000
So it'll print 1230001230001.23000
Admin
TRRWTF here is using Double at all. Remove the decimal point and you can easily store those numbers in a longint. Then you just need integer division and modulus to print the number.
Admin
As someone who works on a system that deals with financial data coded with doubles in a most moron-ish way, I loathe every bit of stupid code that does all sort of math-magic to avoid precision errors, while a standard library class is available for such tasks since day one.
But I must admit, this one is a bit over the top. This guy must be a highly paid consultant... or a self proclaimed guru.
Admin
Though I'm still wondering why anybody woud choose "1230001230001.23000" as a storage format for three floats.
Admin
I'm going to add this: if your decimal point is not FLOATING, then don't fucking use FLOATING point numbers. Use fixed point and scale your numbers input/printing or when doing multiplication or division by other fixed-point numbers.
Example: represent money as an integer number of pennies, not as a floating point number of dollars. ".10" is a repeating fraction in binary, just like 1/3 is in decimal, which is why you don't use floats.
Admin
Admin
... The assumption that all money amounts are in the form of pennies is easily dis-proven. The "cost" per gallon of gas in the US is typically to the tenth of a penny. Using integers to hold fractions of dollars is problematic at best, and difficult to properly extend in the future to higher precision levels.
Admin
Admin
Admin
It's a rather ugly hacky way of creating fixed-precision decimal numbers. The format ("ABBBBB...") is not a WTF; the code that converts from "ABBBBB" to "A.BBBBB" is a bit of a WTF, but on the whole, not as bad as it could have been.
Admin
The system seems to be able to parse floats as the last number in every line is a stringified float.
And yet the first two ones a integers.
And there is no separator between the three numbers, so you absolutely have to know the format: 6 digits for each of the first two numbers, then comes a float.
Weird.
Admin
Captcha: sagaciter... yep, sagacious to avoid them.
Admin
Admin
Admin
Admin
Let's just agree that TRWTF is gallons then and start using litres then.
Admin
What I actually miss is the old measures for spirits, given in fractions of a gill :-)
Admin
Admin
drink faster
Admin
Actually, I've done this sort of thing, before. For good reason.
Consider, for example, a legacy system that was written in a language or on a platform in which their either wasn't a system-standard mechanism for printing decimal numbers, or the system-standard mechanism was inadequate. It'd have been only reasonable for the implementers to have provided their own.
Now consider someone writing a new system either to replace or to interact with that legacy system. The new system may have a perfectly adequate system-standard mechanism for printing decimal numbers - but if it was important that the new system print decimals in exactly the same way that the legacy system did, it's be not at all unusual to duplicate the decimal printing mechanism of the legacy system.
Admin
I'll bite. You are female and I have fallen in love.
Admin
Admin
Actually it does not matter as java will optimize those string operations and replace them with a stringbuilder anyway. With + you get a nicer looking code and java does the stringBuilder optimization for you anyway.
Admin
Yeah! Fuck petrol!
...Stupid petrol.
Admin
One time when I went to the UK, I noticed the "cheap" prices for gasoline (petrol). Then I took a reality check. The prices weren't in $$/gal, they were ££/liter. Then I gagged and muttered to myself, glad to be live in the USA.
As for using floating point for money: Don't. I learned the "hard way" when I submitted invoices and the totals didn't add up at all. Went back to the drawing board, and converted to double precision, and thanked my stars that the amounts didn't get mucked up since I was only using about 1/2 of the precision (which is about all you can use in a floating point number for money!).
As for conversion from internal machine representation to external printouts: 'printf' and its friends are most helpful. Use them!
Admin
JavaScript uses 32-bit int and IEEE-754 64-bit binary floating point. I was developing a front-end for a systemlater cancelled, and I wanted to be able to do decimal arithmetic. To get enough precision, I used floating-point with a scaling factor of powers of 10.
Floating-point can represent some values exactly. If you stick with those values, then you do not have the problem. (Instead, you have other minor problems.)
Sincerely,
Gene Wirchenko
Admin
They need to make sure the function headers are copyrighted in case oracle actually succeeds in their lawsuit against google over android.
Admin
Admin
Token "Java is TRWTF"
Admin
I mean... if it's not as reasonable as a gallon X kilogallon X microgallon, then I won't bother to learn the difference. Have fun remembering how many pints make a gallon (or is it the other way around?), I'll just keep multiplying and dividing by powers of 10 ;-)
Captcha: distineo... extinction?
Admin
"OK, Google. How many pints are there in a gallon?*"
Admin
Admin
I actually know this to be a fact because I was writing code to talk to gas pumps/terminals back in the late '90s. (TRWTF is the goofy 5787 baud rate that Gilbarco pumps used. Good thing we used an SCC chip which had a variable baud rate generator. I think at one point just for fun I got my Powerbook 145's RS-422 talking to Gilbarco's RS-485, or maybe I was trying to make a pump simulator.)
Admin
Admin
Good explanation!
Admin
whoa, whoa. TMI.