⚡ If you wanna learn to code faster make sure to hit subscribe!!!
@Retrodogo3 жыл бұрын
Ok and first
@emilygreen727873 жыл бұрын
Can I say something… ok so my first video I might have broken Alexa I asked her a math question and she said 1.00000000000000000000000000000000000000000000000000000000000000000000000000000000000ooooooooooooooooooooooo and it’s still with this subject because she couldn’t say the whole answer so it has limited ai like he’s saying.
@emilygreen727873 жыл бұрын
And I will sub
@Shad0wBoxxer3 жыл бұрын
Is this with calculators as well
@Коммун3 жыл бұрын
@@emilygreen72787 KZbin Calculator released.
@coompiler90293 жыл бұрын
if (num1 == 0.1 && num2 ==0.2) { return 0.3 } There we go solved it
Finally, I can now show this to mom and tell her I’m better than computers
@yt-sh3 жыл бұрын
no you're not (burp) Morty
@Flame_Dev3 жыл бұрын
Ohhh look whole cartoons are coming together here XD
@newaz12683 жыл бұрын
definitely worth it!
@Nicolas_Payne3 жыл бұрын
Also, this is the reason the far lands occurs/occurred in Minecraft. The farther and farther out you go, the less and less accurate player movement becomes.
@filthyweebs7593 жыл бұрын
You tell mom and she says no more computer for you
@AIM-9X_Sidewinder Жыл бұрын
"your computer sucks at math" calculator: my objectives are beyond your understandings
@SAIHTAM20Y Жыл бұрын
Yeah even my phone calculator is smarter so i dont understand the problem
@flyinhigh7681 Жыл бұрын
@@SAIHTAM20Yany computer can be made to do exact decimal math, thats not what programming languages are doing though, because doing exact decimal math is slow and sucks, doing limited precision binary math is fast and cool, so your computer does that instead. Where precision matters (or where speed doesnt) you can do exact math, hence why a calculator gives the exact answer. Where speed does matter (such as in a computer processor) you go for the faster but slightly more imprecise math, and it is good enough
@qwaeszrdxtfcgvbqwaeszrdxtf5733 Жыл бұрын
Dude all computers are a calculator
@EthanMckinnell Жыл бұрын
@@SAIHTAM20Y the calculator app rounds it, but when it comes to raw computing then yes they are dumb, your phone is still technically dumb however it is hidden
@jesterram71469 ай бұрын
@@EthanMckinnellnah the calc app isn't rounding the incorrect answer it just using a different version of addition. cause it ONLY has to calculate it uses a precise but slow method. since Java and python do way more they're a bit sloppy to go faster
@roua.3 жыл бұрын
today I (finally) learned the meaning of "floating" in floating point. great vid
@okachobe13 жыл бұрын
Same
@jackkirby52873 жыл бұрын
Same
@marflage3 жыл бұрын
Same
@JeekyllFrost7773 жыл бұрын
Same
@shivamprakash67963 жыл бұрын
Same
@morethanjustasloth55282 жыл бұрын
“JavaScript is a toy language, so I tried Python instead.” Hahahahaha
@NZIsaacNZ2 жыл бұрын
As compared to what?
@LordSwordbreak2 жыл бұрын
@@NZIsaacNZ You will C.
@morethanjustasloth55282 жыл бұрын
@@NZIsaacNZ Compiled Languages.
@zezogamer85672 жыл бұрын
Imagine not using java, c++, c, rust, or go CRINGE
@NZIsaacNZ2 жыл бұрын
@@LordSwordbreak as compared to segmentation fault?
@AmanSingh-wk4qu2 жыл бұрын
To be exact, it's a limitation of the IEE754 floating point standard. There are implementation of arbitrary precision floating point libraries (aka bignums) but they're slower and less optimised for modern CPUs
@QuintinMassey Жыл бұрын
I made a similar comment. The person who made the video should attempt to be more precise rather than saying “the computer sucks at math.” It only does what you tell it, so actually you suck at math 😢
@davidgillies62010 ай бұрын
They still can't exactly represent numbers whose denominator is not a power of 2 (dyadic rationals). And by judicious use of SIMD instructions multiprecision libraries such as MPFR can be made much more efficient for calculations close to machine precision.
@__christopher__9 ай бұрын
@@davidgillies620 Computers "suck" at math the same way humans "suck" at math when they claim that 1/3=0.33 or pi=3.14. And yes, you can write rational number types that are exact (as long as neither the numerator nor the denominator overflows).
@TheApeiros8 ай бұрын
Fun fact: IEEE754 also specifies a decimal variant. Just that basically no hardware supports that.
@leovillant7686 ай бұрын
nigum
@Pixelcraftian2 жыл бұрын
_”Good job on solving all of the tough questions, this one is the money shot, what’s 0.1 + 0.2?”_ The computer: 😓
@untitledlecontentfarmerI2 жыл бұрын
i like 0001 0011 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0100
@UnSolved_Myst2 жыл бұрын
Didn’t expect to see you here
@professionalmexican79192 жыл бұрын
@@UnSolved_Myst let the man comment!
@celineragnarto65462 жыл бұрын
How is 0.1+0.2 wrong? What’s the formula supposed to be? I’m still in junior high I wanna learn something.
@uniques.54432 жыл бұрын
if you do ( (0.1 x 10) + ( 0.2 x 10) ) / 10 will give you 0.3
@wanderingbufoon3 жыл бұрын
"Computers use base 2 while humans use base 10" Me: "the future is not now, young kid"
@proxyhx20753 жыл бұрын
I think I understand big guy
@NightFyreTV3 жыл бұрын
Computers actually use base 16 , well. Programs do anyways
@saltytoxicity21723 жыл бұрын
@@NightFyreTV Ehhhm, no Computers are base 2 because they only have 2 states: on and off (current flowing and no current flowing). Machine Code gets printed as hexadecimal (base 16) for readability. Under the hood though, its all ones and zeroes.
@queegle993 жыл бұрын
Interestingly, although base-10 is a very common base in human languages, not all languages use it, so 'humans' in general don't just use base-10
@user-tr8kr1jd2o3 жыл бұрын
@@NightFyreTV they don’t. The state of each bit is still either HIGH or LOW in a modern computer, hexadecimal is just a more convenient way to compress the human readable form of a number while preserving the location (since its very very easy for a human to convert between base 2 and 16 in their head)
@joaovgarcia2 жыл бұрын
damn i wish there was a longer version explaining more on this topic
@eduardogarcia6318 Жыл бұрын
If you're interested on it, you could search on how floating point numbers work. Here's a short and simple explanation, tho Let's say you have 64 spaces to be able to save any number from 30,000 to -30,000 and with all its decimals. It's an insane range for such a little space. So the way to work this out is, exponential numbers. You'll have the 64 spaces divided like this: First one is sign (so you know if it's positive or negative) Next 11 are the exponential And last 52 are the base, or mantissa You can use this to have a very wide range of numbers, because of the exponent, but you only have a precision of 52 bits, so you'll lose information. It's like if we said 3x10⁹ We're able to represent a large number (3 billions) in only 5 spaces, but we can't know if it's 3 billions and 1, because we only have those 5 spaces and we have to get as close as we can.
@PipocaQ Жыл бұрын
You probably remember scientific notation from school, where you write numbers as a*10^b. For example, 5.324 * 10^21. It's easy to build hardware that can add, multiply, etc. numbers of the form a*2^b, given fixed ranges for a and b. This is very fast and efficient, but there are no integer solutions for a and b in the equation 1/10 = a/(2^b).
@lukes3845 Жыл бұрын
Jan Misali has a good video on this. You should be able to find the video by searching his name and “floating point”
@Murzac Жыл бұрын
In all simplicity this is the same thing as trying to write down 1/3 as a decimal. You'll go 0.333333333... but you can never write the full number down because the number of 3's is infinite. 0.1+0.2 in binary just results in the same exact kind of infinite number in binary, so when you convert it to base 10, you see the artifact of this rounding error as the random 4 at the end.
@labadaba5088 Жыл бұрын
Khan Academy lol AP Comp Sci Principles
@marcframe74493 жыл бұрын
create two accounts in your bank. #1 with all your money #2 with 0.1 cents move 0.2 cents from #1 to #2 then move 0.20000000000000004 back to #1 rinse and repeat
@smotbutterman11273 жыл бұрын
Get charged a flat rate of 3 for every movement. Get boned.
@umnikos3 жыл бұрын
That's why all (sanely designed) banking systems use integers to represent amounts.
@Mia-cw1du3 жыл бұрын
@@umnikos czech banks: hold my beer
@leoingson3 жыл бұрын
It's been done with stacking up rounding errors of interest rates - guy got caught, tho.
@TomasNavickas3 жыл бұрын
@@umnikos lol what integers? Max size would be 2 billions. They use bigdecimals
@Justcause6413 жыл бұрын
0.1 is a recurring decimal in binary the same way 1/3 is recurring in base 10. Base 2: 0.1 + 0.2 != 0.3 Base 10: 0.33 + 0.33 + 0.33 != 1.0
@slaitm92893 жыл бұрын
But 0.3 recurring times 3 IS 1.0. And 0.1 + 0.2 is equal to 0.3 no matter the base.
@Henriki23053 жыл бұрын
@@slaitm9289 when calculating with computers there is no infinitely recurring decimals, 0.3 x3 = 0.9, 0.33x3 = 0.99, 0.333x3=0.999, no matter how big amount of data pc can store, the answer pc will get is always slightly less than 1. Same goes for 0.1 since it is recurring in base 2, pc can never store it in a way that is exactly 0.1, the last bit(s) will always be a bit inaccurate and you get a bit over the correct answer
@slaitm92893 жыл бұрын
@@Henriki2305 Should have clarified that you are talking about the implementation in computers. Right now it seems like the errors mentioned in the video are actually correct and just a characteristic of the different base
@flamesnail Жыл бұрын
I know in python it’s fixed with: from decimal import Decimal X=Decimal(‘0.1’) Y=Decimal(‘0.2’) print(X+Y)
@UwOtt11 ай бұрын
Ew
@Zubuu7 ай бұрын
Disgustingggg
@animeblackguy_16943 жыл бұрын
“javascript is just a toy language tho” *church bells toll*
@beatalert1233 жыл бұрын
😁😁
@johnnyplays28433 жыл бұрын
So is python lmao
@monodragon3 жыл бұрын
older versions of minecraft:
@Qbe_Root3 жыл бұрын
@@monodragon That's Java, a completely different language
@TruthAndLoyalty3 жыл бұрын
Theres way too much in production using javascript to call it a toy language.
@michaelpoggers24073 жыл бұрын
To be more specific, its like when you add 1/3 + 1/3 + 1/3 and get 0.99999999 as 1/3 is a recurring number, you store it as 0.33333333 in base 10. Same with base 2, both 1/10 and 2/10 (0.1 and 0.2) are recurring. And when you add 0.5 and 0.25 you'll get a correct result because both are not reccuring in base 2.
@nachnamevorname98013 жыл бұрын
Thanks!
@marflage3 жыл бұрын
This makes total sense. Thanks
@nonconsensualopinion3 жыл бұрын
And to elaborate on your excellent comment, you'll get an infinite recurring number if the prime factors of your denominator are not a subset of the prime factors of your base, or radix. In base 10, the prime factors of 10 are 2 and 5. So we can write 1/2 easily as 0.5 because 2 is in our set of prime factors of our base. 1/5 is 0.2. no problem. 1/4 is 0.25. easy because 4's prime factorization is 2x2. 1/3 is 0.33333333333 forever because 3 is its own prime factor and not 2 or 5. So in computers our radix is 2. So we can only precisely represent fractions with a denominator is powers of 2, eg 1,2,4,8, etc.
@awkwardnerd.3 жыл бұрын
Nah I tried it it gives you 1 as an answer
@beatalert1233 жыл бұрын
Meanwhile: le humans: who let the nerds out, who, who who who 😆
@82NeXus Жыл бұрын
For anyone wondering, the solution, if you want exact decimal arithmetic, is to use a decimal library, such as Python's decimal module.
@webnplay Жыл бұрын
or just use a proper language xD
@neomarrodriguez9255 Жыл бұрын
@@webnplaythis isn't a language problem, this is how computer are intended to work. It's a trade off, you sacrifice precision for efficient math
@bgaabt3 жыл бұрын
"And that's why your computer sucks at math" - the stupid machine can't even calculate an 18-digit number correctly
@softwarelivre23893 жыл бұрын
Until you use bigfloat hehehe
@Kyle-xk2rb3 жыл бұрын
hAvE yOu hEaRd oF BigInt?
@SameerSk3 жыл бұрын
@@Kyle-xk2rb BigInteger java fam
@ignore24663 жыл бұрын
@@SameerSk looOOooong
@tanker2423 жыл бұрын
That's just the limit of the data type you're using.
@whyareureadingthis67193 жыл бұрын
I'm studying python as part of my math course in uni, this is the first thing they told us since alot of out detailed codes could be ruined by these rounding errors
@Sal1981 Жыл бұрын
That's why in Python you use the Decimal type, which stores rounding errors when doing calculations, eliminating them. Pretty important when you do finance calculations or any other calculation that requires +15 digit precision.
@MisterBerdill3 жыл бұрын
Just had a lecture about this the other day! Really interesting stuff, explains a lot of weirdness from my first days of coding!
@enra85573 жыл бұрын
Oh man thanks. I can sleep now
@enra85573 жыл бұрын
@Hand Grabbing Fruits don't call that bug. It's feature
@samygafsi6429 Жыл бұрын
About a month ago I had to struggle with this and it drove nuts. Good thing I had a friend (also a developper but with experience) and he explained it to me. If any beginner encounters something similar : if it's just one or two variables just multiply everything by 10 or 100 or something. And don't forget to divide by that number at the end before displaying the result. Don't try to solve the issue in a very complex way, at least not at the first lessons. You will have plenty of time in the future to do so.
@hackedxd28132 жыл бұрын
JavaScript is just a toy language, so I tried it in Python. Lmao 🤣🤣
@Une6sy2 жыл бұрын
Reject Java embrace C#
@aubrey-levreau Жыл бұрын
It's true tho JS kinda a joke
@hjrgf Жыл бұрын
@@Une6sy i used to code in c# it was enjoyable i switched to c++ took me 4 hours just to install the compiler acidentally used gcc instead of g++ forgot a " so i got errors forgot a ; so even more errors and all of this for hello world
@Une6sy Жыл бұрын
@@hjrgf lmao I’m not very good but stackoverflow has been a good tool and now chat gpt
@webnplay Жыл бұрын
@@Une6sy Reject C# embrace C++
@wasabithumbs62943 жыл бұрын
This is incomplete. Less abstracted programming languages will support "double" and sometimes "BigDecimal" datatypes among others rather than floats. Depending on how stupid you want to get, calculations within a reasonable range will be 100% accurate. This would be suitable for applications like banking or cryptography. Not that it matters anyway, I remember hearing that 9 digits of pi is all that is required to calculate the radius of the observable universe within the size of a hydrogen atom?
@wasabithumbs62943 жыл бұрын
@@codymiller5468 Oops. Thanks!
@terrywright97653 жыл бұрын
As an old school Fortran programmer, I am impressed you know about 'double precision'.
@redberry44203 жыл бұрын
@@codymiller5468 because of how ridiculously small the numbers get though, 39 digits really isn’t much considering the enormity of the observable universe and the size of an atom
@moihawk6663 жыл бұрын
I love this and just said pretty much the same thing ….. #realnerds
@moihawk6663 жыл бұрын
@@terrywright9765 I’m a new school C# programmer and doubles is a basic unit of measurement, we have come so far.
@hudmo4193 Жыл бұрын
Just came through Modeling Methods at university, where we discuss all the ways to circumvent this and other computer problems when performing math ops. Pretty interesting
@yourDecisi0n3 жыл бұрын
I think explaining how to solve this issue would make a great idea for a video :D
@bhaveshladdagiri26753 жыл бұрын
Simply rounding up the decimal places should do the job. For example: a = 0.3 - 0.1 > 0.19999999999999998 a.toFixed(2) > 0.20 p.s. toFixed might return a string so you can simple do parseFloat(a.toFixed(2)) to get a number
@raiyansarker38093 жыл бұрын
I don't think it is an issue, computers work like this. It has nothing to do with programming languages!
@zyansheep3 жыл бұрын
@@bhaveshladdagiri2675 also rational number specifications that support fractions
@skynliner34343 жыл бұрын
@@bhaveshladdagiri2675 dude parsing is slow, it shouldn't be a general solution. jsben.ch/yCfVY
@t_kon3 жыл бұрын
Simple answer, you don't. In general, if you can avoid floating point then avoid it. Only use it if it's necessary.
@inactiveaccount48293 жыл бұрын
Just watched on of your threejs vids as I’m learning about 3D rendering for fun as I usually spend my day on JavaScript algorithms. Your tutorial style is super easy to understand, and they’re fun to follow. Appreciate my guy
@asherrfacee Жыл бұрын
You can factor out the lowest common multiple of ten required to remove the floating point in order to force it to use integer addition for the highest precision possible. function sumPrecise(a, b) { var tens = 0; while(a < 1 || b < 1) { a = a * 10; b = b * 10; tens++; } return (a + b) / Math.pow(10,tens); } console.log(sumPrecise(0.1,0.2)); // 0.3
@marc-io2 жыл бұрын
It's funny that he assumed JS was broken and thought python wouldn't
@amberwingthefairycat Жыл бұрын
I’m pretty sure he was already aware of this rounding issue and he just wanted to have some fun
@JacobSantosDev Жыл бұрын
The difference is that there are precision options in Python... And JavaScript and other languages
@oscardbg9654 Жыл бұрын
what about JS sorting method... it outputs [1,11,111,2,3,4] i.e.
@JacobSantosDev Жыл бұрын
@@oscardbg9654 I think that problem is between keyboard and chair
@oscardbg9654 Жыл бұрын
@@JacobSantosDev lmao, it seems you haven't seen that before, I hope you can declare an array and use the sort method... Try it and you'll see that "bug" idk but works in a weird way
@kjn59913 жыл бұрын
"Javascript is just a toy language".... congratz, you just triggered over half of developers following this channel :D
@joaomendoncayt3 жыл бұрын
There's 2 types of JS devs here. The ones who will laugh at his joke and the ones crying because he "offended" his favorite tech ahahah awesome.. this guy is a genious
@cenacr0073 жыл бұрын
aye
@huaweiespionandotudo86373 жыл бұрын
But it's
@wasabithumbs62943 жыл бұрын
I mean, there's a reason people usually move onto JavaScript (maybe python) after Scratch, rather than C languages for instance
@juliaf_3 жыл бұрын
@@wasabithumbs6294 there's also a reason why python is so widely used. It's easy to write and easy to understand. As long as you don't care about speed, it's nearly a perfect language. I'd recommend starting with c++ or c# before Python though cause it's easier to learn other languages if you know a c language than python
@RockSleeper2 жыл бұрын
unexpectedly and gratefully learned why it's called floating point, thanks.
@Hiatuz42 жыл бұрын
I love this channel. He's like a guy that randomly pops up and tell you useful info that will help you in the future.
@smotbutterman11273 жыл бұрын
My computer also sucks at choosing things randomly. Can you make a video about that too, bro?
@chrismesogitis93103 жыл бұрын
It can't produce any unpredictable number because in its core the commands and the circuit is specific so nothing unpredictable can come out of it.That's why it produces pseudo-random values who are predefined by a complex function to seem random.
@priyanshusharma67633 жыл бұрын
This is normal bro :`)
@jackkirby52873 жыл бұрын
True. Pseudo randomness is randomly not random
@sankalp25203 жыл бұрын
just add an analog device to read white noise, like an oscilloscope when its probes are left in air, it shows random signal.
@sankalp25203 жыл бұрын
but i think pseudo-random numbers are more useful than random numbers. U can create the exact set of pseudo-random numbers if you know the seed value.
@rubansrirambabu77712 жыл бұрын
As part of one of our assignments, we had to compare and do arithmetic with floating point values as well, and it was very important that we accurately compare two floats. One solution most of us thought of us was to do the comparison and keep a small tolerance level to make up for IEEE 754 representation of floats. My friend decided to just implement a class that represents floats as rational values (in the form a/b, where a and b are ints). It works well, however you won't get a lot of precision, not as much as float.
@DerpDahFlerp3 жыл бұрын
First time I've seen a computer programming video and felt proud of my own knowledge. Small win, but I'll take it!
@doggo_woo2 жыл бұрын
I learnt about this watching a video explaining why in serious Sam the weapons slow down after a while. The reason was because the weapons used a timer with a float data type
@kaspermaaa3 жыл бұрын
"javascript is just a toy-language" *tries python*
@brotherindeed9923 жыл бұрын
I use c and i think this hasn't happend to me ever but too lazy to try C++ gand forever.
@strawberrysausageinc3753 жыл бұрын
Python... Does it even Count AS a real language ?... Its as easy as Scratch... Okay... Nevermind... They told us in Computer Science Lesson, that scratch is a Programming language... So yeah... I guess Python counts
@cherryramatis25083 жыл бұрын
@@strawberrysausageinc375 well, google use python for basically 60% of it's system, so I think it counts
@strawberrysausageinc3753 жыл бұрын
@@cherryramatis2508 Just curious... But where do you get that Numbers from... How do you know ?
@strawberrysausageinc3753 жыл бұрын
@@mesoseven1633 I guess its weird to Use if you are Not used to using library's for basically everything... It doesn't realy matter what you want to do... You have to understand how the Library you need for the Project works... and Not all of the Library's have good Documentation
@Cathay3520 Жыл бұрын
teacher "you only scored 40% in the test" me "lemme show you something"
@fatgolem693 жыл бұрын
now i know that my computer sucks at math Thanks Fireship
@EJ-jh1vf2 жыл бұрын
POV: you are about to go look at .1+.2 in JS and Python
@Lampe2020 Жыл бұрын
We should create a more calculation-error-resistant number format to replace floats and doubles, like store the number before and after the decimal point, prepended with a header of 6 bits that tells the bit where the after-decimal-point digits begin. Then convert the whole thing to any other number base when needed.
@erichahn33362 жыл бұрын
Base 2 is not the problem. You would have the same problems for base-10 floats. The actual problem is that the mantissa and the exponent have a limited amount of bits available to represent a float. This means that on the real axis floats are weirdly scattered and since operations on floats must return floats we will get rounding errors.
@athingwhichexists2 жыл бұрын
was typing this up but decided to check if someone else was going to point it out, thanks man. All the base 2 does is make the errors bigger after converting back to base 10, but the errors were already present in base 10 to begin with thanks to trunkation
@edgaredge39713 жыл бұрын
Just keep track of your significant figures and decimal places and it will always be correct. All good scientists and math mathematicians use sig figs when multiplying and decimal places when adding to cut out all the uncertainty in their figures. This video shows a prime example of why you should have only rounded to the first decimal place.
@Mrcake01032 жыл бұрын
...what? Significant figures are for keeping track of the uncertainty inherent to real world measurement and guesstimates. Very little of that (if any) applies to mathematics. “Idunno dude, like, pretty close to 2” is not an acceptable answer when the actual solution is the square root of 9.
@zaid6527 Жыл бұрын
Same precision error is there in pow() function in c++, because it uses double arithmetic, that's why we use modular exponentiation for precise calculation.
@kevinfuller972 жыл бұрын
I remember finding out about floating point and just like being absolutely mind blown how extra but necessary it was
@shan_singh2 жыл бұрын
"Javascript is a toy language" me wo spent hours learning it : 👁👄👁
@siliconhawk2 жыл бұрын
learning anything takes time tbh
@codewithsheikh28052 жыл бұрын
It's use to be now it's almost multi general purpose language
@gawizard49802 жыл бұрын
hours?
@androdeveloper72612 жыл бұрын
@@gawizard4980 XD :-D
@androdeveloper72612 жыл бұрын
So have you stopped wasting your time ?
@overcritical304 Жыл бұрын
That is why CPUs have an option called "Rounding Control". Or RC register.
@Julioyowyo3 жыл бұрын
Thanks! Now I know the practical answer to 3D problems I've found for decades and not knowing what!
@idontknowwhatimdoing89413 жыл бұрын
Damn and i was gonna send my computer to take my math exam instead of me, thanks Fireship.
@Rinael222 жыл бұрын
You literally have the best content for programmers, both entertaining both full of information. Thank you for all your efforts
@somebrid21473 жыл бұрын
If JS is a toy python needs to fall under the same category imo.
@Tyler-jd3ex3 жыл бұрын
no brackets = weird
@somebrid21473 жыл бұрын
@@Tyler-jd3ex agreed. It even won an award for readability..
@Tyler-jd3ex3 жыл бұрын
@@somebrid2147 PYTHON???? the spacing is hell
@abhinavjha30823 жыл бұрын
@@somebrid2147 Might as well fucking use English at that point
@NoName-oi6vw3 жыл бұрын
@@abhinavjha3082 englishScript: The function dance will make the computer dance If your mom is stupid, dance **Computer starts dancing**
@MisterDan3 жыл бұрын
When we designed the Sheerpower real data type we put the integer part of numbers into one memory location and the fractional part into another. That stopped the penny errors:) Of course Sheerpower is a computer language for business... so it was well worth the effort!
@zanehannan53062 жыл бұрын
So basically fixed point? Makes sense, if a little awkward. A good alternative is fixed point within the typesystem, but that takes time, effort, and compile time trickery to make it work no questions asked with little to no memory excess for storage.
@MisterDan2 жыл бұрын
The developer does not change their code, so not awkward for them. Transindental functions, rarely used in business applications, are handled by the runtime engine converting to and from F64.
@MisterDan2 жыл бұрын
It did take a year to support it all seamlessly.
@WorBlux Жыл бұрын
The traditional approach is Binary coded Decimal, or BCD
@TheFrangalista2 жыл бұрын
I remember attending a seminar on software testing and hearing the instructor carrying on at length about this "bug" that she had found in excel and the calculator app. As you mentioned, the IEEE-754 standard does use floating point and it does represent numbers as binary. Regardless of the numeric base, however, there are always some fractions that cannot be reasonably expressed without an infinite number of digits. In base 10 for instance the numbers 1/3 and 2/3 result in infinitely repeating digits following the decimal point. Even on paper, we cannot represent the values exactly and any calculation on these values will show an error because of rounding. It shouldn't surprise us that there are similar fractions in base 2. I think that what takes us by surprise is that 1/10 is one of those values. If we were doing the same calculation by hand, we would have that same difficulty. The only real reason we say that the computer sucks at math is because our brains can recognise the repeating pattern more or less and work through it to the precision we require. The computer can be instructed to do this and, within the ranges provided by 64 bit floating point, can provide ample precision for the vast majority of applications. In short, this is not an earth shattering bug but is something that we have to be mindful of regardless if we're using a computer, calculator, or working out the problem using pencil and paper.
@fletchedfps3 жыл бұрын
His face when he learns to cast numbers as an int data type :O
@giga-bowser3 жыл бұрын
Then it wouldn't be a decimal. You could technically do (1+2)/(float)10 but you have to cast the 10 as a float so it preforms the division correctly.
@shanegrayson70683 жыл бұрын
@0:49 omfg, I remember using that site for my Architect course. Was super helpful.
@carcedopro7285 Жыл бұрын
you actually can solve the issue in python by using decimal which is Base-10, for example: from decimal import Decimal print(Decimal("0.1") + Decimal("0.2")) # Output: 0.3 You should always use decimal for sensitive calculations
@gurbux64913 жыл бұрын
"JavaScript is a toy language." had me in splits 🤣
@KingTeravolt3 жыл бұрын
Wonderful, fantastic, educational video! *Now if only I understood anything that was said*
@TheWhiteMamba3000 Жыл бұрын
I have always wondered why when using the functions in Excel, there will be extra numbers as a rounding error. However, if you manually enter the equation instead of a function, it tends to be more exact.
@bjornnilden2603 жыл бұрын
This is why you never use floating point when you need accuracy.
@uwufemboy56833 жыл бұрын
If you need accuracy to the point that would be affected by floating point rounding errors, either you’re doing quantum mechanics or your code is shit
@MrRFPinhas3 жыл бұрын
@@uwufemboy5683 lol yeah
@lu_ck3 жыл бұрын
@@uwufemboy5683 or you're dealing with bignums?
@DoorknobPlus2 жыл бұрын
@@uwufemboy5683 or if you are a bank
@thecandybarbandit3 жыл бұрын
Nobody’s gonna ask why he needed a calculator to solve that problem?
@ShiniestMeatManKrieg2 жыл бұрын
Better question: why didn't he use a calculator app on bis computer ?
@delavegamarvin24432 жыл бұрын
A workaround I've learned is to store the whole number and fraction to string. When you calculate the numbers, convert the strings to Decimal(C#) and apply calculation. This way you can have a very high precision number implementation.
@debapriyasinha113 жыл бұрын
When you forgot a float property in python 😂😂
@Dan_ny3 жыл бұрын
"JavaScript is just a toy language" Triggered :)
@TuringTested013 жыл бұрын
Its a joke...he knows javascript is literally one of the best languages out there :)
@jackkirby52873 жыл бұрын
@@TuringTested01 next to Java, that is ;)
@TuringTested013 жыл бұрын
@@jackkirby5287 java is too verbose in my opinion...gets annoying in large projects....also i love the functional programming in javascript and how it handles asynchronous tasks with async await
@vishalmakhija26163 жыл бұрын
Python gave the same result
@SourceEnginePlayer Жыл бұрын
that animation is perfect
@Galimeer52 жыл бұрын
That explains a lot, actually. I do a lot of Skyrim modding, and one of the things I do to make sure custom spells/enchantments are working properly is to set their magnitude values (or percent chance of activation) absurdly high for testing. I tell the program to use 99999 and it gives me 99999.00001 or something. Never really knew why, and ultimately it doesn't really affect what I do, but it's interesting nonetheless.
@pavfrang2 жыл бұрын
You can avoid (in-non scripting languages) floating point arithmetic by using "decimal" (fixed-point decimals) types. Fixed-point decimals are using integer arithmetic (but they are limited to some decimal digits) so there are not such issues in theses cases. For example, in C#: 0.1m+0.2m -> returns 0.3m (decimal type) without any rounding error. That's one of the reasons that decimal/numeric types are preferred types in databases, especially for "money" related values. The equivalent in console means: console.log( (1+2)/10 ) --> 0.3 (precise) @fireship
@nathanberrigan9839 Жыл бұрын
This is why a lot of financial systems don't use floating point, but instead store money as an integer number of pennies (or milles) and then throw in the decimal on the display.
@Swesh3 жыл бұрын
I demand a Trial by Combat for telling "JS is just a toy language"! 🗡
@ArthurKhazbs3 жыл бұрын
I agree: toys are at least supposed to be fun to play with
@fadious_padious27113 жыл бұрын
Hahaha. Hope you never have to deal with two systems that speak different floating point standards.
@lodestar3984 Жыл бұрын
I feel so proud of myself for knowing this. I learned this in my Comp. Sci. 1 class.
@xrayian3 жыл бұрын
Toy language had me laughing till the end of the video
@collinthomas62883 жыл бұрын
the shade
@naveedalirehmani41353 жыл бұрын
"javascript is a toy language" oh God as a web Developer this hurts on a personal level but seriously talking I am a software engineer and a web developer and all the people who think it's a toy language need to go see a doctor
@joaomendoncayt3 жыл бұрын
you are so naive ='D
@TopBagon3 жыл бұрын
Nah they need to go see sharp
@zeroww73 жыл бұрын
in the next scene he shows freaking python lmfao that is even more toy looking
@rmaster9343 жыл бұрын
He was joking...? I mean, this channel does many cool Javascript stuff so...
@treeplate512 Жыл бұрын
this is a real problem when making a calculator, half of the actual calculating is correcting for floating-point errors with string manipulation
@murugappanm98833 жыл бұрын
I was so confused when i came across this issue. turns out nobody cares float is not very precise. banking and scientific calculations make use of fixed point decimals apparently.
@whisper__3 жыл бұрын
They certainly do not :) Especially banking. All of your money is stored as integers in pennies/cents.
@aemmelpear57883 жыл бұрын
scientific calculations are often done with normal double precision floats as well. Modern CPUs are pretty good at floating point arithmetic and thus quite fast. Since speed is often crucial for scientific software the tradeoff of using normal doubles is often beneficial.
@kittymedusa36183 жыл бұрын
@@whisper__ Why can’t you use bigfloat with two decimal digit precisión ?
@FalioV3 жыл бұрын
@@whisper__ That's actually not true. Every good programmer knows the variable used for money is "decimal", because it has the smallest deviation at big numbers.
@whisper__3 жыл бұрын
@@FalioV Integer has no deviation at all...
@dummypg61293 жыл бұрын
Well, who doesn't really suck at Math?
@zyansheep3 жыл бұрын
Euler
@RaefetOuafiqo3 жыл бұрын
me and some good mathematicians out there
@pipassinsal63043 жыл бұрын
behold the legendary mathematician silvi rae
@marquez24473 жыл бұрын
Pipas sin sal jajajaja
@killerbunny89502 жыл бұрын
Hi! I accually recently ran j to this problem while programming a project. You can acctually fix this problem by using "decimal" instead of a "int" or "double" The trait-off is that decimals cost more resources to do math with
@nomadshiba3 жыл бұрын
this would have been a great introduction to BigInt, and bignumber.js
@wubsyman57962 жыл бұрын
Essentially how Floating Point works (under IEEE 754) is that an 8bit value (can be more but it's the same process) is broken down into a 5 bit mantissa and a 3 bit exponent these two values are essentially the multiplier (exponent) and the value (mantissa). A three bit exponent would be -4 2 1 meaning it can go from +3 to -4 and it dictates where the "floating point" goes. The mantissa is a bit strange as it depends on where the "floating point" is to determine its values as a number line, essentially it works like a decimal point but in binary so if the floating point is more to the left then the value will be more precise (more values on the right means it can go to lower fractions) but if it goes more to the right then it allows for larger numbers. For example: 01000001 01000 = Mantissa 001 = Exponent -4|2|1 0|0|1 = 1 space to the left generally the default numberline with 5 bits is as follows: -8|4|2|1|1/2 however since we left shift thanks to the Exponent it becomes this: -4|2|1|1/2|1/4 now we can input out mantissa: -4|2|1|1/2|1/4 0|1|0|0 |0 = 2 therefore with IEEE754 (normalised but I won't get into that since it's a whole thing) it is safe to say 01000001 = 2 Note: This is just how I was taught using "Craig and Dave" as well as UK A-Level Computer Science spec
@servo-skull94502 жыл бұрын
Idk why or how this was recommended to me but im forced to learn coding now
@zonictrout Жыл бұрын
One of us One of Us One of Us
@LordSplynter3 жыл бұрын
Depends, when it comes to speed and precision computers are still the way to go, when it comes to theoretical mathematics that requiere a higher undestanding of advanced math, then humans have the supirior hand, simply because computers arent there yet, but in the next decades they will be and it would be interesting to see a base10 version of a computer systemized learning application in a base2 computer, kind of like a modification or a simulation of a realistic mathematical procedure, like a programming language but for computers to communicate with humans. I went to far with this lol, would be cool tho
@blmb42742 жыл бұрын
I guess, but how can transistor to transistor logic computer,(basically on and off) become base 10, the reason it is base 2 is since, they turn on or off.
@lovelycity15042 жыл бұрын
@@blmb4274 Our precious scientists and engineers could try to make an advanced photonic chip, rather than using the electrical chips. Maybe photonics can help humans advance past binary
@siliconhawk2 жыл бұрын
I'd think computers will probably evolve with 2^x base tbh. that's just me but I'd assume its way easier to go say base 8 or base 16 rather than base 10
@LordSplynter2 жыл бұрын
@@siliconhawk huh, well you might be right, that goes waaaaay too out of my league of knowledge to be honest, but might be plausibe
@TypeScriptTV2 жыл бұрын
Very informative! I learned a lot in just 1 minute. 🙂
@amadddd03 жыл бұрын
I never knew that's why it was called floating point. ❤️ Years of computer science schooling and work and I still learn things everyday 🤣
@noobynoob138 Жыл бұрын
Computers aren't bad at math, computers are bad at human math. It's like asking a human to lay eggs
@SantaClaauz Жыл бұрын
Cope
@rubocky6126 Жыл бұрын
"Computers aren't bad at math, Computers are bad at human math. It's like asking a human to lay eggs" - 🖥
@noobynoob138 Жыл бұрын
@@rubocky6126 I am human person [replypart2]
@DR-54 Жыл бұрын
computers can only do logic, everything else it does is mimicking operations using logic gates. This means that if you wanna make something more efficient and handle larger numbers, you get 0.30000000000000004.
@sachinkainth95082 жыл бұрын
This is why languages like C# have decimal types for doing such calculations.
@gmlviper Жыл бұрын
I know I'm late, but: "Computers don't suck at math, you suck at computers" There, fixed it.
@Rabbinicphilosophyforthewin Жыл бұрын
Best answer.
@QuintinMassey Жыл бұрын
I’m a EE and I approve of this message. They only do what you tell them to. So, yes, he sucks at computers… and math.
@triliner2549 ай бұрын
@@QuintinMassey He explains why computers dont suck, if you actually watched the video.
@QuintinMassey9 ай бұрын
@@triliner254 you obviously missed what is being said in this thread. Maybe it’s a bit beyond your capacity.
@whackedoutcookie43932 жыл бұрын
Lost me about 10 seconds in. I'm currently writing this as some strange unrecognizable language is playing in the background.
@vii-ka Жыл бұрын
in floating point math, any number is not a number and actually means the range of numbers too small to be distinguished from this number
@shemseddine32052 жыл бұрын
“JavaScript is just a toy language” The World Wide Web: “Am I a joke to you?”
@Nebulisuzer2 жыл бұрын
WWW is made with HTML, not JavaScript
@coronaklledmebot48562 жыл бұрын
u sound cringe
@newtykip2 жыл бұрын
@@Nebulisuzer JavaScript provides functionality to websites
@DMSBrian242 жыл бұрын
@@newtykip and it's the worst possible choice for it, unfortunately modern web is in fact a joke
@adil67233 жыл бұрын
JavaScript is toy language 🥲🥲
@tanmay______3 жыл бұрын
True
@alex_chugaev3 жыл бұрын
TypeScript is the beast
@alex_chugaev3 жыл бұрын
... only if you're a kid
@abh1yan3 жыл бұрын
@@alex_chugaev naah..no javascript no typescript
@ShinyRowletGuy Жыл бұрын
"I like your funny words magic man"
@sasidharan44603 жыл бұрын
Ok I am early
@desox78913 жыл бұрын
Hi early, I'm dad!
@syafiqsharif23 жыл бұрын
🤣
@PRIM3053 жыл бұрын
Same
@TheLifeMusicYT3 жыл бұрын
same my g
@thisisbadpanda3 жыл бұрын
😂😂😂😤
@CardenDioxide Жыл бұрын
I have no godamn idea about what he just said, but he got me interested to watch the whole short ;-;
@dinodude5184 Жыл бұрын
The Waffle House has found it’s new host
@spongebobseyelashes854811 ай бұрын
It’s cause of the IEEE754 floating point system. It calculates the sign, mantissa (basically the number represented between 0 and 1) and the exponent with bias. The issue arises with binary, as the calculation is ultimately done there. 0.3 and others will have rounding issues due to repeating patterns, so the computer isn’t able to precisely compute it. Therefore it does as good a job as it can with the mantissa bits, and then rounds the ending which is why you get the weird number at the end
@spongebobseyelashes854811 ай бұрын
I recognize he put this info in there but I legit took a 216 class this semester and number representations is a big part sorry
@Thrarm Жыл бұрын
well when i go to google and type "0.1 + 0.1" and the built in calculator shows up it works fine
@punnup3452 Жыл бұрын
Actually this shows off a really cool thing about decimal systems in general Base 10 makes sense to us because we've always had 10 fingers and we also have two hands so it's easy to divide by two but it then gets difficult as it turns into 2.5 if you divide again But when working with base 2 (binary) It's as simple as 1 to 0.1 to 0.01 But of course this comes to the problem of translating 0.1+0.2 because 0.1 and 0.10 are not 0.1 and 0.2 but rather 0.5 and even If you tried adding them together into 0.11 that is just 0.75 First you would have to translate 1/10 into binary meaning you're going to have to make the sequence of ones and zeros (representing half quarters eighths 16th and so on) (And according to Wikipedia sense I'm to lazy to do math it's 0.00011001 so yes more complicated than just 0.1) and then 2/10 So the discrepancy is most likely the mathematical equivalent of sending a sentence through Google translate a few times before reading out the sentence
@Saxophonin Жыл бұрын
For python you can use the decimal module.
@haim0z Жыл бұрын
Actually in C you can manually set the integers to doubles, long floats, and other floats to be way longer than languages like python and JavaScript
@at-sushi Жыл бұрын
In past I didn't care that, but in competitive programming situation decimal problems are VERY annoying. They needs epsilon to compare decimals each other.