Комментарии:
Math.abs((0.1 + 0.2) - 0.3) < Number.EPSILON
ОтветитьI always code it like
Float apple = 0.1;
Float banana = 0.2;
float potato = 0.3;
Void THE_MATH(){
If apple + banana != Potato{
Kill_myself();
}
}
All languages except COBOL, and other languages with built-in decimal type.
ОтветитьAww man. And here i was thinking it was a concatenation meme.
Ответить"911 what's your emergency?" "math isn't mathing in JavaScript"
ОтветитьSirf 19 ,20 ka hi tu farak ha 😂
ОтветитьLooks familiar to the if statement in JavaScript...🤔
Ответить!yes = no
ОтветитьTrue
Ответитьisnt this interpreted right to left? meaning this is equal 1.1
ОтветитьAs someone learning js and html and css more moving from other languages and tools I first ran into this the other day and it bothered me a lot. I made it round my number * 10 and divide by 10 to make sure it doesn’t happen again, but it probably still does and I’m just not gonna log it and I’ll sleep fine as long as I never do
ОтветитьFalse
ОтветитьIt's because to a computer 1 is not really 1.
It's 1.0000000000000001 or something.
So when you say 1 == 1 they might say it's false in some programming languages
!=
ОтветитьTry use ~~
Ответитьit has to be != not !==
ОтветитьIts just not possible.
ОтветитьA programmer has a problem. They decide to use floating point numbers. Now they have 1.99999999991 problems.
Ответить"Don't try to bend the spoon. Realize... there is no spoon" ahh moment
Ответить😅
Ответитьfor those wondering, that's the strict comparison operator (data types must be the same)....just missing the IF statement
Ответить! == ?! Я знаю только ! =
Ответитьtrue
Js😵💫
Why?
ОтветитьWhat is this language? Mostly unequal writed as !=
ОтветитьThis is like a calculator giving you 10+12E or some shit when on the graph its clearly 0
Ответитьmy stupid ass thought that was a factorial so i had to double check
ОтветитьNumber.toFixed(2)
Or however many decimal places are significant.
Bro i thought it was 0.2!
ОтветитьIt should be != no?
ОтветитьTrue
ОтветитьThis is just a problem with floating point numbers in general. Remember to tolerance your equality checks. C++ has a useful tool for this in the form of std::Numeric_Limits<type>::epsilon()
ОтветитьUse ints instead of floats.
ОтветитьNot a js thing, its global
ОтветитьSomehow I read it like:
0.1! + 0.2! == 0.3!
Why not != like a float plus a float is obv going to be a float no need to make it be strictly equal to
ОтветитьWhy are you even comparing float?
ОтветитьPhp dev spotted 🤦
ОтветитьWait I'm floated
ОтветитьIsn’t this should be 0.12?
ОтветитьWhy this issue??
Ответитьconsole.log(0.1+0.2)
0.30000000000000004
That's just IEEE floats.
JS, Java, C++ whatever.
Array.prototype.sort() 💀
ОтветитьAgred
Ответитьfelt the 2.9999999999999991 😭🙏
ОтветитьI hate that I don't just understand but that I can feel this from personal experience...
ОтветитьMath.round()
ОтветитьWhat?
Ответить