Комментарии:
(1+2)/10
trolled
The IEEE flag for compilers is a lifesaver. Coming for someone who writes scientific applications on supercomputers, it's a pain in the a$$
Edit: Forgot about 17 digits. You'd need 16 bytes then. So long double should work.
Meanwhile Excel =SUM() function done this peacefully 😆😆
ОтветитьSong name at the end?
Ответитьbro just use a double :sob:
Ответить0.1 + 0.2 = 0.3
Ответить1 attemp only: I guess that the final 4 is something about the bits (is a float number, then it has 4 bits of lenght)
ОтветитьDamn, that’s annoying.
ОтветитьNo wonder my conversion from farhenheit to celsius was wrong
Ответить❤❤❤❤❤
ОтветитьThe reason is because of the floating point representation in computers. Since computers only store binary numbers some small errors are introduced when doing the conversions. If you want to learn more about it you can search IEEE 754 representation of floating points for starters.
Ответить"Python help me out here" is such a mood 😂
ОтветитьI actually suffered a similar bug in a production system that was supposed to work on really small percentages (which again blow up to be big after being multiplied by number of clients which ran in 100s of millions). This was in a big 3 software firms.
And I was a new hire.
"Ohhh, whaatt the fuck" sounds too relatable
ОтветитьAcho que consegui...
ОтветитьWhat about to use long double. I know it's very implementation defined but why not to try?
For example, clang supports 128-bit long double on software level when using some compilation flag...
What IDE do you use???
ОтветитьIEEE-754, baby :). Try having fun with some floating point DSP code. Shout if you get a denormalized number ;)
Ответитьguy went ask help to Java LMAO
ОтветитьIntegers are your friend.
Just assume that integers are tenths.
1 + 2 = 3
limited attempts is literally hell
ОтветитьFor my great suprise C# actually gets this one right.
ОтветитьNow I'll be honest, you did one thing wrong, you used pure float in C, you should have gone with long double (128 bits).
Ответитьwell, you could have used a more mathematical proof
1+2=3
so by dividing everything by 10
(1+2)/10=3/10
so, by printing the result of (1+2)/10, I thing you would have been able to get the level of accuracy you want, since it will be adding ints rather than floats
I just started learning how to code today, so I have no idea of what I just watched...I do know he fucked up tho😂
ОтветитьAren't Floats designed to be warped so it's more accurate closer to zero, and less accurate at super high numbers? But because of the warping, .1 + .2 would never actually equal .3, would it?
This challenge was impossible to begin with.
why are you using argc and argv if you're not going to put any arguments in your program?
ОтветитьBro it's just a bonus, don't force javascript to do what it can't for just a bonus.
Ответитьfloat problem tho.
ОтветитьWhy « int argc, char **argv » in your « main » ? …
ОтветитьMaybe mess around with compiler settings, study the floating point standard?
ОтветитьYou make coding fun again. Re ignited the fire in me. Thanks bro from christchurch new zealand. Chur
ОтветитьIEEE 754 shenanigans be like
Ответитьinsane? i was insane once. then they trapped me in a room. a rubber room. a rubber room with rats. the rats made me insane
ОтветитьWell, you see...
0.30000001192092896, if rounded, will still be 0.3. So arguably, C answer is still correct.
Use Ruby: "0.1".to_r + "0.2".to_r == "0.3".to_r
=> true
... Subscribed to save the sanity ¯\_(ツ)_/¯
IEEE754 standard for finite precision floating point. In C, "float" is usually 32-bit single precision. For your 2nd and 3rd attempts, those were double precision.
ОтветитьEasy. Just convert to a string, append more zero's and convert back to int.
Ответитьi find it funny that i only know why this happens because of an sm64 video
ОтветитьStill now almost all hardware level programming done by either C or C++..
So my favourite language for bit Byte and register level Access...
Should have used doubles or long doubles.
ОтветитьJava Masterrace would have saved you
ОтветитьTbh it's not really a C problem, inaccuracy is an inherent property of all floating points numbers... but it's fast so who cares?
ОтветитьComputer can't do math because the memory is limited to 32 bit or 64 bit 😂😂
ОтветитьDoes anyone have the technical explanation of why this is the case?
Ответитьthis thing won't work because in C floating-point numbers are represented using binary approximations
so you gotta use gmp or whatever, pick your poison buddy
Printf your original answer and tack on (concantonate?) a string of 15 zeros.
Ответить