- 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
What would be the problem if input is negative? It should work just as fine.
At least they aren't doing it like
Admin
Before coffee.... negate(-2) == -2 - (-2*2) = -2 - (-4) = -2 + 4 = 2.....
Admin
Let me guess - there will be a Part II tomorrow: someone noticed that the result are not exactly the same (because René accidentally fixed the rounding errors), so it had to be quickly reverted back in a production hotfix.
Admin
It's a really good idea to write out exponentiation correctly, because at the moment that I read the article, it said that this method causes problems when the number is greater than two hundred and fifty two, which is epic nonsense. (It's for that reason, combined with the epic conflict between Markdown and the various exponentiation operators and the conflict between ^ as exponentiation and ^ as XOR, that I favour writing it as
pow(2.0,52.0)
...)Admin
Also, re inflation. The worst episode of hyperinflation so far (Hungarian pengő between August 1945 and July 1946) got as far as
pow(10.0,29.0)
from end to end, so it's definitely worth consideringpow(2.0,52.0)
which is "only" aroundpow(10.0,17.0)
Admin
Multiplying a double precision number by two won't be a problem until the expoent overflows, that is, until ~10^308 there is not loss of precision at all.
Admin
Bah, our stylesheet clears the
sup
tag.Admin
return value - value - value;
Avoids the overflow problem.
Admin
This strikes me as related to home-grown date functions. Instead of using the built-in multiplicative inverse (* -1), let's invent some new way.
Or, we could use time-tested functionality that already exists...Good for Rene to fix that up.
Admin
Er, no. Negating a thing gives the additive inverse. The multiplicative inverse of x is 1/x.
Admin
Depends on whether the FPU / software FP / whatever keeps spare bits around during the subtraction. If it doesn't, you may find the case where the original mantissa ends in 1 to be a problem.
Admin
We are currently having issues as the values coming in from our Indonesian office in Rupiah are too large for our old finance system, so...
Admin
Admin
What if the OS in use can't express the value '2' exactly in its floating point routine? (2.000000000000000000016936)
Admin
return (value - value) - value);
I'm a subscriber to the explicit order of operations school instead of relying on language-dependent implicit ordering. Makes the intent absolutely clear and no gotchas when you have to use multiple languages.
Admin
Man, they really doubled up on the negativity, didn't they?
Admin
Who the heck refers to negation as 'reversal'?
Admin
I'm still waiting for hyperinflation of the Vietnamese currency. Imagine the global sense of penis envy ...
As for "Sometimes, finance falls into (a) similar place," I think that's an underestimate. I'd go with "statistical certainty." What's interesting to me, having painstakingly spent a year reducing each and every possible POS format to the essential lexical, syntactic, and even semantic rules, is that it's quite possibly to boil down decades of Business Analyst gibberish into something like 500 A4 pages, with circles and arrows and neat little tables on each one.
What's even more interesting ... I suppose ... is that the out-sources charged with re-implementing the system chose to take those 500 pages and reinflate them to the original set of total gibberish, but on a different platform.
Well, I say interesting.
Admin
Someone with no clue of mathematics, obviously. Such people handling our finances is not very reassuring.
Admin
As he story goes about Jantje meeting his old math teacher. Teacher: Hey Jantje, You had so much troube with math so how are things today? Jantje says: I'm buying things for a dollar and sells them for 10. On those 10% I make a good living.
Admin
Still better than that horrible Discourse thing you guys adopted a while back.
Not that I don't appreciate Meta-WTFs. Oh wait ... I didn't.
Admin
Such complicated ways of doing it in JS :)
Me, personally, I like:
:)
Admin
Using floats instead of decimal for currency is another big WTF here. Of course JavaScript doesn't have a decimal type to use because JS is also a WTF. But you could use a 3rd part library like moneysafe.
Admin
Value * (1 - 2)
Admin
If they were wanting to avoid overflow, they may as well have cancelled out:
and gone with just:
But that was too obvious and difficult for them, after all.
Admin
It was fun submitting an expenses claim for over 10,000,000 rupiah a few years back.. when it was worth more .. as it was for a week in a quite nice hotel in Samarinda, East Kalimantan. Wish I had taken a copy of the receipt.
Addendum 2020-05-13 06:24: That would have blown away using a 32 bit integer .. or somebody trying to store money in a single precision float.
Admin
... snart enough to know x - 2x = - x, but not smart enough to realize that x * -1, or even 0 - x, achieve the same thing in a much more straightforward way. interesting.
Admin
//Everything you love in one function function negate(a) { a.indexOf("-") < 0 ? a="-" + a : a=a.replace("-",""); return a; }
SCNR
Admin
Surely the right way to do this looks more like
Sheesh! kids these days!
Admin
The real WTF, and I'm surprised and disappointed nobody else mentioned it, why is this even a function at all?
Admin
But if you're going to do negVal = (val - val) - val, why not just do negVal = 0 - val? Or negVal = val * -1? This last one you could even shortcut, assuming language support, with val *= -1.
Admin
TRWTF is that JS already has a unary minus.
Admin
this reminds me of an old story about an astronomer who tried to write his own "planetarium" program. his biggest mistake was using a separate FILE for EVERY SINGLE STAR. it worked, but it was terribly slow.
Admin
Nobody should story money in an integer or in a 32 bit float. But treasury valuations in rupiah are rounded to 1000 -- by contract, not just by convention -- dating from when treasury transactions were done in pencil, rather than in excel.
Also, 'reversal' is what you do when reversing a transaction, and , as noted above, x-(2*x) gave a different value on a pre IEEE 754 fixed-point mini-computer, as used at one time for currency transactions, which caused specifications to be written that way.
Admin
I think an accounting person would consider Negation a "Reversal" as in "Reversing an Accounting Entry". Maybe?