- 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
ok, now lets say the next number has an extra digit - are you going to re-write all your code because you came up with a ridiculously non-flexible design?
Saying "something more precise...." is a complete cop out. Either name what this "something" is, or accept that you don't have the answer.
I work in finance, and valuing things to numerous decimal places is common place. floats work fine for this purpose.
Admin
(wtf x y) // x has been proclaimed as TRWTF for an instance of y on this site. (beatsUp x y) // x would win in a fight against y. NO CONVERTING TYPES Y, THAT IS CHEATING! (hat? x y) // x and y wear the same hat
Admin
Really? I wonder why every major RDBMS has a money type in that case.
Admin
Admin
If you are in finance and evaluating things to arbitrary decimal places, can I have a float until Friday?
Admin
To be honest, though, I don't know if evaluation of a pointer as a Boolean implicitly compares it to the literal 0 (and so always compares to the true null pointer) or if it treats it as an integer type. I would expect the former, though, so a compiler that didn't do this would be non-conforming.
Admin
Then again, I do wonder if sometimes the real issues with using floating-point currency aren't real issues for the application or the business. And I always have to laugh when the "anti-floating-point-currency" folks stubbornly argue their case in the presentation layer.
Admin
Interesting...
Admin
I would have the C pointers with NULL work like: An implicit cast from a constant 0 is NULL. An implicit cast from any other number, or a non-constant 0, is a compile error. An explicit cast from any number to a pointer is the corresponding address, so 0 might not necessarily be NULL. An implicit cast from a pointer to boolean is true if and only if it is not NULL. An implicit cast from pointer to number is a compiler error, but an explicit cast works and 0 will not necessarily be NULL.
Admin
No, let's keep it simple. How do you store 0.2 in a binary floating point field? It winds up being 0.001100110011.... You're storing an approximation of the number, which means your books won't balance.
That's why DBMSs generally have a decimal format where you can specify the number of digits you need.
Admin
I wish the hoare that I frequent would charge me null
Admin
i feel like a real null forgetting to quote...
Admin
No wonder the financial system is crap.
Admin
Money? Floating point?? Fail!!
If you want to do money, make sure that the programmer who does it uses his OWN paycheck as beta test. Then when it agrees with the manual calculation and verified by a nice higher up (don't want errors in the wrong direction), he gets paid. If there are ANY miscalculations, the IRS gets involved, and they don't take kindly to "round off error" as an excuse.
Yes, I did some money calculations in floating point. It didn't take long to find out that single precision was bad. Thankfully the money amounts weren't too high enough for double precision (actually REAL*8) to make drastic errors.
You see they invented Cobol for a reason!
Admin
So do you invoice people for $101,491.3954928211 on a regular basis? And then hound them if they are .000000000001 cents short of what they owe? Keeping track of sub-penny amounts seems pointless when you can only be paid in multiples of pennies. It just gives rise to a situation where sum(what we were owed) <> sum(what we were paid) even when everyone has paid you everything you asked for. What do you do with the incremental difference? Do you carry it forward to the next month and try to invoice for it then, hoping that the customer won't notice you are invoicing them for 1 penny more than they see on their monthly usage report?
Admin
Floats are terrible, because you cannot precisely represent 0.1 in binary, which is very common in financial transactions. This leads to things like
0.1 + 0.1 = 0.1999999999999
Admin
If your DBMS provides it, there is this nice data type called MONEY. You want to use the MONEY data type to store money, not numeric(18,12) or (6,2) or some other homegrown approximation. Money data types are fixed point instead of floating point. In sql server it goes out to 4 decimal points. In Informix you can specify a precision up to 32 or something crazy like that.
Admin
I think the confusion here is between Finance and Accounting.
Finance can use floating point to calculate things like componding interest rates, while Accounting deals with the actual transactions that take place in integer units.
Some of the highest FLOP supercomputers are owned/used by financial companies, for doing market speculation... (i.e. no direct value to society)
Admin
Admin
Admin
VB.NET hasn't killed that many of my brain cells. Yet.
See, I didn't even notice the missing colon. Back in the early eighties, overlooking something like that could result in a horrible death.
Admin
Yes, that is what we tell our customers when the amounts we show are wrong by a penny. We're like what the fuck man, who cares it's just a penny. That is why we are the dominant software company in the world.
Admin
Me thinks you needs to submit a sample case as a future WTF. At the very least it sounds like an example of what happens when wanna-be's code with too many beers between the keyboard and the chair.
Admin
Admin
Admin
Surely, though, if you really need a static method, you could say:
If object 1 is null, then we are equal if object 2 is too. Otherwise, we can call Object 1's equals method.
I sort of thought the whole OO think was about dealing with objects directly, so if we have obj1 outside the static method, we presumably know whether it is null or not (or we can trivially check), and then we can compare it using the .equals method
The code itself works in the WTF, no doubt about that, but it's whether there's any point to it that remains to be seen. Sometimes you have that moment where you think: "Why was I trying to reinvent the wheel?"
Admin
I nearly got caught!!
Hi Nagesh!
Admin
Admin
Another financial worker throwing in my 2.00000001 cents.
When I worked in banking (e.g. user accounts, business transactions, SWIFT...) we used precise money types.
Then I moved to Wall St. I don't know any execution management system (at any brokerage firm or quant shop) that doesn't use plain old doubles. The problems don't exist in real life. Numbers have "clumped" precision (if that makes sense). A small number can happily be rounded. A large number (that matters) isn't going to have any decimals and gets happily rounded too.
Any pennies missing would get noticed. We need speed: doubles give us this with no loss.
Admin
C's Null is simply a pointer to nowhere (or to a place that has been defined as nowhere). This is a far better approach than assigning a pointer that actually points somewhere. I'm not really sure what you mean about the validity of it...A Null Pointer is a perfectly valid pointer (same as 0 is a perfectly valid integer), but what's the alternative? Setting a pointer to something invalid would be akin to setting an integer variable to "Fred". I find the statement that the null pointer is valid but an error somewhat confusing. Any value that the pointer can take must be valid, thus of course the null pointer is a valid pointer, it simply points to somewhere we shouldn't be doing anything. The Null pointer is not considered an error condition by the operating system, trying to use the memory it points to is considered an error condition. This is very, very sensible is fou ask me.
Maybe it's because I've grown up with C, I think there's a certain amount of sense in initialising a variable (irrespective of type) to some known and consistent value.
We should keep in mind that in C things don't (by default) get initialised to any particular value (ok, it might be compiler specific), so NULL is optionally used by programmers.
Oh, and did I just get trolled?
Admin
Yeah, but off somewhat more than 6 beers.
Admin
I always wondered why I never get many presents on my birthday, must be because its on a "null"
Admin
Sorry, i had to do this (the java specification implies that 2 nulls would return false, which conflicts with the specification of the exercise [my old teacher was a stickler for the specification]):
Admin
Apart from the other problems already mentioned in the second set, in what case would you ever need this logic?
Admin
That's where sprintf() and atof() come in...
Admin
Wouldn't
be false (if a is not null). Based on wot you sed about the spec^n, we only have to check the nullity of a....
(how does the java spec imply that 2 nulls would equal false? Surely this whole idea of a static comparator is not very javanesque?)
So...couldn't we have
Admin
TRWTF is log4j. It really is time now to move to SLF4J.
Admin
Also, I recommend using Guava and Objects.equal().
Admin
TRWTF is Java.
Captcha: validus - yes, I'm right.
Admin
Admin
Admin
Or worked in a multinational company. there are countries that requires 6 correct decimal places for money, even if you toss 1000000000 amounts around. Our system has a homebrewed "Money" class that even takes care of rounding problems that occur when dividing say 10 by 3.
Some places are anal about silly stuff.
Admin
TRWTF is
Obj1 does not exist and obj2 does not exist, so they are equal? Of course not, they don't exist. Equality has no meaning for objects that don't exist.
The Other WTF with checking for null in equals methods is that the programmer expects to compare uninitalized objects. I can't imagine circumstances where that is not a bug in the calling code.
Admin
TRWTF is using float for money. Geez, precision is so unnecessary when dealing with money, right? (Can I have one cent from each operation ane call it rounding error?)
Admin
Akismet, you stupid robot.
Admin
That's very meta of you, Nagesh.
Admin
So... it's not, quite indeedleeo, not useless? Not that I couldn't care less.
Admin
Of course you're not sure. The type system doesn't tell you enough to be sure. Null pointers are enforced by convention rather than the type system, which is a reasonable hack for C.
What's truly insane is trying to formalize that convention into null references in Java.
Except that, according to man malloc, if malloc returns a null pointer, it's an error condition.
Union types? Exceptions?
I think you were trolled by K&R.
You say you grew up with C, and you say memory should be initialized to some known and consistent value. In the next sentence you explain that C doesn't initialize values.
Instead of initializing pointers to something that isn't a useful value but is rather, at least sometimes, an error condition...
Why not have pointers be initialized with what they fucking point to? Maybe I've been using too many fruity computer sciencey functional languages, but I would have thought that's the calling, the reason, the raison d'etre, the vocation, wait for it, the "point" of a pointer.
If it's perfectly natural for you to assign meaningless values to all your variables because your language doesn't initialize memory by default, yes, you're affected by the inanities of your language. Sure, if I'm implementing an entropy pool I don't care if my buffer has stuff in it, and if I'm explicitly scanning memory or rolling my own IPC, I'd want that. C is doing the wrong thing 99.999% of the time by default, and you're taking that as the natural way of things.
Admin
Admin
Augh! The flash! It burns my eyes!
Thank goodness I have flash block, or I would have had a sudden enormous spike in CPU usage. Flash on linux freaking sucks.