Absurdism corner

Why?


  • Total voters
    194

Binky

Death's Steed
Staff member
Joined
May 28, 2003
Messages
6,911
Location
16A (TO)
The young lad/lass up there looks like a quick learner. I know that with that sort of early-years education, we can prevent children becoming IoT developers.

Talk to your kids about web security - before someone else does.
 

FBnil

Ready to Champion the Pyra to the World...
Joined
Dec 14, 2012
Messages
2,805
Location
Yurp
HTML:
javascript:var a=function(){alert(0.1*0.2); }()
put that into your URL (if you have FireFox)
 

jparish1977

Member
Joined
Oct 1, 2016
Messages
79
Age
42
HTML:
javascript:var a=function(){alert(0.1*0.2); }()
put that into your URL (if you have FireFox)
Is it the pseudo url, floating point math, alert dialog, or firefox that you find the most absurd? (Now I have to remember which machine I have firefox on to see if it does something unexpected)

Sent from my SM-N950U using Tapatalk
 

Binky

Death's Steed
Staff member
Joined
May 28, 2003
Messages
6,911
Location
16A (TO)
HTML:
javascript:var a=function(){alert(0.1*0.2); }()
put that into your URL (if you have FireFox)
Iceweasel 38.5 here. Nothing happens.

I'm curious to know what you'd expect to happen. Presumably something absurd?
 

Djoga'Ro

moonstruck
Joined
Apr 3, 2016
Messages
980
HTML:
javascript:var a=function(){alert(0.1*0.2); }()
put that into your URL (if you have FireFox)
Pale Moon 28.5.0 here. Nothing happens.
[doublepost=1558171230,1558171131][/doublepost]Maybe absurd are we, trying it, expecting something to happen and getting confused. ?
 

jparish1977

Member
Joined
Oct 1, 2016
Messages
79
Age
42
I assume the expectation is an alert dialog displaying a slightly inaccurate value on browsers that support javascript pseudo urls

Sent from my SM-N950U using Tapatalk
 

FBnil

Ready to Champion the Pyra to the World...
Joined
Dec 14, 2012
Messages
2,805
Location
Yurp
@Binky @Djoga'Ro It would popup an alert dialog with "0.020000000000000004" and an OK button. The floating point of JS is not that good.

I have an old FireFox, maybe they removed it in the new FF. Try Waterfox instead, it worked there.
 

WizardStan

Mega GP Mania
Joined
May 24, 2008
Messages
16,733
What is "not that good" about it? Do the same thing in C and you get 0.02000000141561031341552734375. That's just the nature of floating point numbers in a computer, you can't represent an infinite precision decimal, you can only represent "close enough", and if you'll notice, the JavaScript output is actually closer to what you'd expect than the C. Or is that the "not that good"? That it produces a different result than a true IEEE754 representation should?
 

levi

Still fresh, damnit!
Joined
Oct 6, 2008
Messages
11,378
Location
Somewhere off the coast of the EU
You mean an infinite precision binary number, presumably. In decimal, the answer is 0.02 exactly, or 1/50 (because you're calculating 1/5 x 1/10). In binary that's slightly more than 0.00000001 (1/64), presumably an infinite precision binary, and when you try to store that in floating point, you effectively try to shift the decimal until the number becomes an integer; all of the digits are to the left, but with an infinite precision or simply too precise number that's simply not possible so it truncates it at its maximum resolution,

You could argue that this would be better if it used a decimal mantissa, so that it stored 2x10^-2 exactly, but in terms of the transistors and things inside a chip, when you have to divide by 10 it's relatively a killer. Dividing by 2 is simply a matter of shifting the bits one stop to the right and discarding the carry (also known as an ASR; an arithmetic shift right), which is easy to do in terms of transistors and traces. To divide by 10 (110 in binary) you're asking it to do long division every time, so it would be much slower. A slight loss of precision is usually considered preferable; in the javascript you're only out by something like 2.842170943040401e-14% (according to python's limited maths ability)
 
Top