Back To Basics! Fixed Point Numbers in C++

  Рет қаралды 62,650

javidx9

javidx9

Күн бұрын

Пікірлер: 213
@SojournerDidimus
@SojournerDidimus 2 жыл бұрын
29:38 your circle circumference is 35 and a bit in 4.4 format, but in 4 bits you cannot represent 35, is the compiler cheating and using a bigger type during constexpr evaluation?
@javidx9
@javidx9 2 жыл бұрын
Lol great observation! Absolutely gonna investigate this!
@BeheadedKamikaze
@BeheadedKamikaze 2 жыл бұрын
Aren't all the registers on modern CPUs at least 32 bits? So it wouldn't necessarily overflow.. and maybe the intellisense is not masking the bits so it reads it as a 32-bit int? 🤷
@javidx9
@javidx9 2 жыл бұрын
With the help of some nerdy discordians, its been identified that intellisense may be playing a few tricks! I might do a follow up about this.
@SojournerDidimus
@SojournerDidimus 2 жыл бұрын
@@javidx9 thanks!
@andrewdunbar828
@andrewdunbar828 2 жыл бұрын
@@javidx9 Please do!
@pauldirac5069
@pauldirac5069 2 жыл бұрын
Thanks gigachad
@allmycircuits8850
@allmycircuits8850 2 жыл бұрын
My favourite explanation of 2's complement is treating most significant bit with "minus" sign. In this video, instead of weights 1,2,4,8, let's think of 1,2,4,(-8). Then 1001 becomes -8+0+0+1=-7 indeed. Easy to see that -8 = 1000 is biggest negative number in that representation and 7=0111 is biggest positive number.
@NDAtheist
@NDAtheist 2 жыл бұрын
To add to this, my favorite way to count negative in binary, if I don't want to use the 2's complement algorithm (for example, I'm counting on my hands or just inspecting a number visually), is to assume all 1s (e.g., 1111) is -1, and then count down from there with zeros. So 1110 is -2, 1101 is -3, 1100 is -4, and so forth, up to 1000 which is -8. It's almost exactly like counting up in binary, except you start on -1 instead of 0.
@flatfingertuning727
@flatfingertuning727 2 жыл бұрын
@@NDAtheist An even nicer way I think is to figure that if you start with *any* number whose e.g. 16 lowest bits are all zeroes and subtracts one from it, the result will have ones in the 16 lowest bits. If one starts with a number were the million lowest bits are all zeroes and subtracts one, one will get a number whose bottom million bits are all ones. If ons starts with a number where an unbounded number of the lowest bits are zeroes and subtracts one, one will get a number with an unbounded number of ones in the lowest bits. The upper bit in e.g. 16 bit two's complement isn't "negative", but instead represents the state of that bit and all bits to its left.
@andyashton7061
@andyashton7061 8 ай бұрын
A rare KZbin educational video with no BS and solid content - Thanks!
@emilycs8823
@emilycs8823 2 жыл бұрын
This is great they never taught me this in school. I ignored my professors recorded lectures and learned C++ from your videos anyway.
@javidx9
@javidx9 2 жыл бұрын
Well give them a chance! There's not a great need for fixed point numbers in reality these days, so I can understand it not being on a syllabus. Cheers!
@VincentGroenewold
@VincentGroenewold 2 жыл бұрын
I absolutely love these basic dives, wrapping my head around conversions and number spaces was always tricky. I knew how to do it, but never really understood what I was doing. And that always doesn't sit right for me. Thanks!
@KweenAhlem
@KweenAhlem 2 жыл бұрын
We adore you teacher you are the best no kidding
@javidx9
@javidx9 2 жыл бұрын
Thanks Kween!
@mrbaeman39lolman60
@mrbaeman39lolman60 2 жыл бұрын
Javid, you're really cool. I enjoy watching you explain concepts in C++.
@TheSulross
@TheSulross 2 жыл бұрын
back when the Intel 80286 was the mainstream processor I wrote 32-bit fixed point math functions (in assembly language) and then implemented a matricies math functionality on top of that - was embedded into a very prominent desktop publishing software package and used to process render graphical image objects. Turned out to be a superb solution for a time when hardware floating point support in CPUs could not be assumed (nor SIMD)
@mick5108
@mick5108 2 жыл бұрын
I have learned so much from these type of videos on this channel, the way he breaks everything down and puts samples of code with it really teaches the fundamentals. If he did the best optimisation and everything it would be way too confusing and only the experts would be able to follow along. Please keep these videos coming!!!
@csgowoes6319
@csgowoes6319 2 жыл бұрын
I hark from the days of 8-bit processors that had no native ability at all to handle decimals, multiplication or anything much in the way of maths, so it was interesting to get an understandable explanation of how programmers might have got around such limitations, though I imagine for the most part they used various approximations to avoid decimals altogether, look-up tables, that sort of thing, it was amazing really what people were able to achieve. It blows my mind that modern processors can do these operations natively, millions of times a second.
@javidx9
@javidx9 2 жыл бұрын
Well that's exactly it. The ingenuity of the programmers before us to make the world work with integers approximating everything is incredible.
@csgowoes6319
@csgowoes6319 2 жыл бұрын
@@javidx9 I do know that the original Playstation didn't have a maths coprocessor and couldn't handle floating point, which is why the graphics constantly shifted around the way they did, because they were constantly using approximated/rounded numbers. As I was just a kid using a Commodore 64 I didn't really know much, but what I do remember doing is programming bouncing ball effects by generating a sine function from BASIC and poking the rounded values into memory and just using them as a lookup table (in Assembly) for the Y coordinates. Pretty sure that's still how demo scene creators do most of the really clever effects on the 8-bits - using pregenerated look-up tables, it's always going to be the fastest way.
@SojournerDidimus
@SojournerDidimus 2 жыл бұрын
Ah yes, I remember implementing long multiplication in assembler because my controller had no hardware multiplier nor enough memory to load the library's multiplication routine.
@richardericlope3341
@richardericlope3341 2 жыл бұрын
The PS1 issue you noticed is not because of fixed point math. It was because of the fact that the PS1 used a simple affine mapped texturing as opposed to perspective correct texture mapping.
@bignope5720
@bignope5720 2 жыл бұрын
@@richardericlope3341 that's why the textures shift and warp, but the 'vertex-snapping' he's referring to **is** because the GTE used fixed-point maths i'm pretty sure - or at least contributed to it.
@pixelpoppyproductions
@pixelpoppyproductions 2 жыл бұрын
Love these videos. There’s a lot of interest in coding for older hardware- which rarely has fast or accurate FPUs, if they have it at all. Good resources like this are priceless imo.
@thatluminary
@thatluminary 2 жыл бұрын
Oh god, I wait impatiently for these. I am new to C++ and the Back to Basics series is very helpful. Thank you
@cthutu
@cthutu 2 жыл бұрын
Fantastic approach to teaching binary, floating point errors and fixed point math. As a mentor myself, I try hard to find ways to approach technical subjects in order to teach them. I will be using your approach for this topic. Thanks.
@scottalexgray
@scottalexgray 2 жыл бұрын
I plan to use fixed point numbers for increased determinism when synchronizing variables across a multiplayer game, so that there is less drift and less server reconciliation needed. Pretty much the perfect video for what I need
@rsa5991
@rsa5991 2 жыл бұрын
As long as you using the same code on both ends, floats should be completely deterministic.
@scottalexgray
@scottalexgray 2 жыл бұрын
@@rsa5991 And with rigid bodies where the physics system does it's thing?
@rsa5991
@rsa5991 2 жыл бұрын
@@scottalexgray As long as you do the same operations on the same values in the same order - the result should be exactly the same. And if you don't do that - fixed won't help you.
@scottalexgray
@scottalexgray 2 жыл бұрын
@@rsa5991 Mmmm, my tests would say otherwise even when everything is in the exact same order (same function for determining the players next position)
@rsa5991
@rsa5991 2 жыл бұрын
@@scottalexgray That means something changes between the runs. Do you use a constant time delta, or calculate it from real elapsed time?
@veto_5762
@veto_5762 2 жыл бұрын
I love the way you explain, it just makes topics that would feel mundane after a while somehow interesting all the way through!
@rfdave3980
@rfdave3980 2 жыл бұрын
Thank You David. Always Learn something new. I enjoy your videos. Back to basics.
@bkmodx
@bkmodx 2 жыл бұрын
THIS is what I expected to see in College when started to go on math lessons. Your brain man it's made to understand numbers.
@dr3d3d
@dr3d3d 2 жыл бұрын
i really appreciate this, currently learning x86 assembly and now I understand why division is handled differently.
@LuigiElettrico
@LuigiElettrico 2 жыл бұрын
I use the fixed point numbers a lot in my design of sound synthesizers and audio effects in C/C++. FP-s are really cool :)
@chrisroode
@chrisroode 2 жыл бұрын
I'm gonna give you a premature thank you for kickstarting my software engineer career. I haven't gotten a job yet...but i'm tryin!
@omerfaruktokluoglu7380
@omerfaruktokluoglu7380 Жыл бұрын
Thank you for video. I was looking articles and try to understand the what and how the fixed point is working, this video is the best for the understanding how it works. At least for me.
@allmycircuits8850
@allmycircuits8850 2 жыл бұрын
When going from bigger format (like after multiplication) to standard one, it is preferable to round it correctly. In case of 4.4 which after multiplication becomes 8.8, it means adding 0.00001 and only then truncating. That's not a famous banker's rounding but seems OK for all practical purposes. It might seem strange to care about last digit that much. Come on, if it really matters then you use too little numbers, so use 32 bits instead of 16, or 64 instead of 32. But my experience tells huge difference, not just 1 bit. Point is: proper rounding leaves us with random errors which tend to cancel out in lengthy computation, or at least make zero mean error and some random noise. But truncating instead of rounding generates SYSTEMATIC errors which don't cancel out at all! And final result is biased. Sorry for "rant", but found it out hard way...
@footballCartoon91
@footballCartoon91 2 жыл бұрын
i tried so hard recently to figure out how to round off numbers.. it is so coincidence the video tells me how to do that.. for my purpose i just want three decimal points and an integer.. after some calculation.. i need 16 bits to represent my floating point number because in opengl it needs 32 bits floating point data type instead i want to use 16 bits because it will save some memory.. in other example i need only 6 decimal places.. with and one integer value between one and seven and another data type with 6 decimal places integer value between 100 and 103 so this will save me some memory
@3f006
@3f006 2 жыл бұрын
Best teacher ever 🖤 Greetings from Brazil
@javidx9
@javidx9 2 жыл бұрын
Thanks Rodrigo!
@3f006
@3f006 2 жыл бұрын
@@javidx9 can you send me some tip of slopes in AABB collision? Like Megaman X Also, I'm doing a Bomberman like with olc ^^
@BradenBest
@BradenBest 2 жыл бұрын
10:35 an observation I'd like to make is that 1111 is 15, and 0111.1000 is 7.5, which is exactly 15 / 2. Shifting right is akin to division by two, so it works out conveniently in that you would have to do no special math to do the division. 15 / 2 = 11110000 -> 01111000 = "7.5" Same for 2.1. 17 / 8 = 2.125. And 9.6, 1001101 = 9 x 8 + 5 = 77, 77 / 8 = 9.625. If it's unclear where / 8 is coming from, it's a shift right by 3, and 2^3 is 8.
@MCLooyverse
@MCLooyverse 2 жыл бұрын
4:02 IMO it would be more clear here to say that, since were limited to 4 bits, we disregard carrying to the 4th (non-existent) bit -- rather than saying there is no carry. By the way, for those who don't fully understand signed numbers, what we're doing here is arithmetic modulo 2^(# of bits). The reason we choose the range [-8, 8) rather than (-8, 8] is because it allows the MSB to serve as a quick sign bit to tell you if the number is negative. We *could* choose 0000 to represent *any* multiple of 16, 0001 to represent any multiple of 16 plus 1, etc. With unsigned numbers, we've chosen everything to be zero times 16 plus the relevant amount, and with the standard signed numbers we've chosen 0000-0111 to be the same, but 1000-1111 to be -1 * 16 + the relevant amount.
@juantouceda3484
@juantouceda3484 2 жыл бұрын
Glad to hear from you again!
@andrewdunbar828
@andrewdunbar828 2 жыл бұрын
I worked out many of the things you show about fixed point math on my own as a kid aged 12 to 14 when I was doing Z80 machine code programming in the early '80s. I didn't know any of the proper terminology of course. I didn't do division though and I think I might've had some kind of more primitive biasing. Can't remember it all these days and I'm definitely less smart now (-:
@zxuiji
@zxuiji 2 жыл бұрын
12:10, something confuses me about this representation, if we've rounded 0.625 up 1 bit to represent 0.1 then how do we know this doesn't represent 0.125 instead? Having come close to a full bignum implementation using just pointers to arbitrarily sized arrays I'm fully aware of the biased exponent, sign, NaN, Inifinity, -0, the mantissa that has the most significant bit chopped off since it's assumed to be there 9 times out of 10, but the rounding bit is where I struggled to get it right, could you elaborate on this part please.
@minirop
@minirop 2 жыл бұрын
Easy. You can't. You lose information (pigeon hole principle)
@satibel
@satibel 2 жыл бұрын
If you want to know this doesn't represent 0.125, you need more resolution on the decimals.
@RA-NAF
@RA-NAF 2 жыл бұрын
Great video. You've created a very simple Fixed Point class that does its job. Another cool thing to add would be a natvis file to see the proper floating point number in the VS debugger (by converting it to float for the debugger). I'm still impressed that the standard library doesn't have a fixed point class given how important that is for a deterministic cross-platform physics engine.
@donovan6320
@donovan6320 2 жыл бұрын
The problem is that most physics engines don't care about being cross-platform and deterministic, usually at best want to be cross platform. Not to mention the limited range and the decently problematic working space requirements mean higher cost multiplication.
@RA-NAF
@RA-NAF 2 жыл бұрын
@@donovan6320 Well, it's a trade off. Higher cost multiplication, but on the other hand, you can have cross-platform multiplayer games that only spam player inputs on UDP packets. Slightly more expensive physics in exchange for significantly less bandwidth and latency in certain types of multiplayer games.
@RA-NAF
@RA-NAF 2 жыл бұрын
@@h..h Fixed point faster than regular floats? As you can see in the video, fp division/multiplication isn't a single instruction like floats are, so they are slower. But, my experience with them is that they are not that much slower. And yes, you would want to use udp. Lost packets aren't a problem when you are constantly spamming them (one of them will arrive. If none arrive, then you got no internet connection). The idea of reliable-udp is that you keep spamming the same packet over and over again until the player gives you a confirmation that it was received. It uses more bandwidth, but latency is much smaller.
@RA-NAF
@RA-NAF 2 жыл бұрын
​@@h..h I'm saying that fixed point math isn't single instruction for multiplications/division. Floats are single-instruction. Both are accessing the registry. Fixed point math isn't faster than floating points, otherwise everyone would use it instead. And TCP is much slower than UDP because it needs a confirmation that the packet was received, which is increasing the latency unnecessarily. It's best to just keep sending non-stop at least 15x per second until the other user confirms the packet was received. This is a common networking strategy, and we got libraries like ENet and Raknet that does that for us.
@RA-NAF
@RA-NAF 2 жыл бұрын
@@h..h the difference is that on TCP we only send the packet once and wait for the confirmation. We only send it again after we confirm that the user didnt receive, so that's a lot of delay between attempts. On reliable-UDP, we don't wait for the confirmation to send it again, so there's a lot less delay between attempts (in exchange for a lot more bandwidth being used since we need to send the same packet lots of times).
@onogrirwin
@onogrirwin 2 жыл бұрын
Been subbed to you for a long time, and I'm just now seeing this video, 3 weeks later.
@mbineshaq
@mbineshaq 4 ай бұрын
Awecome video! I enjoyed watching it. Just wondering what platform did you use to draw. Doesn't seem like a touch screen! Is it one of those Wacom sketch pads?
@javidx9
@javidx9 4 ай бұрын
Thanks! Yeah, a wacom intuous 4
@jhbonarius
@jhbonarius 2 жыл бұрын
Afaik you could just write d*(1
@mohab2018
@mohab2018 2 жыл бұрын
Great videos. I just have an advice. You can sync the audio coming from the mic near you with the videos where you are appearing in it. Because the audio from the mic near you is better than the mic of the camera.
@theforthdoctor7872
@theforthdoctor7872 2 жыл бұрын
back in the 80s I did this to write a 3d rendering engine on my BBC Micro (and yes I was trying to see if I could write an Elite clone). at the time this was the only solution because there was no floating point support and it was fast. it would be a great demonstration of just how good modern floating point is. if you were to change your 3d code to use fixed point and do some timings. i know this is a lot of work because you would also have to write a trig library. but it might give the young players some insight as to how much we take for granted these days. great video btw.
@donovan6320
@donovan6320 2 жыл бұрын
The problem is that they're just not very good for most modern 3D applications. The sheer amount of register space and required temporary bit space make it not worth it, and the fact that floats with hardware acceleration are pretty much as fast and more space efficient.
@theforthdoctor7872
@theforthdoctor7872 2 жыл бұрын
@@donovan6320 agreed, I was thinking in terms of an academic exercise. I remember at university, a post doctorate was working on a system of plug and play real number representations, so you could switch between hardware floating point, rational and interval etc. On the fly.
@donovan6320
@donovan6320 2 жыл бұрын
@@theforthdoctor7872 interesting, sounds rather neat.
@andrewdunbar828
@andrewdunbar828 2 жыл бұрын
Back in the '80s when we used fixed point for this stuff we used lookup tables for trig. Radians instead of degrees. Normalize your input to the range of your table and always scale the result down, never up. Sin and Cos can use the same table of course. My stuff never needed Tan or any of the Arc* stuff.
@donovan6320
@donovan6320 2 жыл бұрын
@@andrewdunbar828 I am aware, problem is for modern games, those techniques either in part or whole would often not work well or be limiting. The kinds of things expected from 3D, even 99s era 3D require higher precision in lighting.
@astroid-ws4py
@astroid-ws4py 2 жыл бұрын
Need to watch it a few times and then implement it, Thank you very much !
@anonymoussloth6687
@anonymoussloth6687 2 жыл бұрын
Will you do floating point numbers next? Like the IEEE 747 standard, mantissa, etc? I studied this in college but never really understood the concept. Your videos really solidify these concepts. Thank you!
@Dave_thenerd
@Dave_thenerd 2 жыл бұрын
See this video by Simon Dev: kzbin.info/www/bejne/haCbap6Fq56jjM0
@johndeleon8741
@johndeleon8741 2 жыл бұрын
Best video ever explaining fixed point, big thanks! Have you thought about making a video explaining floating point?
@charliegallie2026
@charliegallie2026 2 жыл бұрын
Really nice video, I would've never thought to learn about this otherwise. Thanks :)
@wolpumba4099
@wolpumba4099 2 жыл бұрын
Now I would like to see application and discussion of this Idea for fast Fourier transform. And also dual numbers x+\eps y to compute the derivative of algorithms and possibly the error.
@TheMaginor
@TheMaginor 2 жыл бұрын
You can get around using a twice as large integer type as an intermediary during multiplication if you do something like x*y = ((x>>n)*(y>>n))n)*(y & m) + (x & m)*(y >> n) + ((x & m)*(y & m))>>n, where n is the number of bits after the decimal sign, and m is a mask looking like 0b00001111 that selects the bits after the decimal sign. This is useful if you want to use your largest integer type as the base type.
@SimonvandenBroek-zl5jp
@SimonvandenBroek-zl5jp Ай бұрын
how would you do this if you didn't have the double option? would we create functions like FP(value infront of decimal, value behind decimal). that both get an integer ? I am asking because the only reason i'm interested in this is because of cross platform determinism.
@a123-e6r
@a123-e6r 2 жыл бұрын
Hey Javid! Your videos are the best! I have a question though, On your RayCastWorld video, I seem to have a problem when I try to texture the walls with sprites. It gives me an error message on the olcPixelGameEngine header file. It says, "Exception thrown: read access violation. THIS was nullptr." What do I do? Thanks!
@footballCartoon91
@footballCartoon91 2 жыл бұрын
that means this pointer is pointing to null..this pointer refer to current object...open the olcPixelGameEngine header file and navigate to the line where the error throws exception at.. probably you need to override some base class in your class implementation and assign it some values
@a123-e6r
@a123-e6r 2 жыл бұрын
I sort of just started to program with C++ so I am not sure how to do that. But thank you!
@javidx9
@javidx9 2 жыл бұрын
Hop on the discord, much easier to post code examples than via YT. Though sounds like you are accessing something that doesn't exist.
@a123-e6r
@a123-e6r 2 жыл бұрын
WOW!!! Ok, so I found out I put the image in the wrong file. So....that explains it. Thank you so much!
@bangbangskeetskeet7631
@bangbangskeetskeet7631 2 жыл бұрын
Hey man, what are your thoughts on Linux? Do you use it?
@javidx9
@javidx9 2 жыл бұрын
I use it occasionally. I prefer Windows.
@Lion_McLionhead
@Lion_McLionhead 2 жыл бұрын
Today's discovery was constexpr, though the lion kingdom doesn't know why the compiler can't discover that itself if the arguments are constant & it has the inline keyword we already had. Fixed point became a lot more relevant when the STM32F was discontinued.
@gedaliakoehler6992
@gedaliakoehler6992 2 жыл бұрын
“I’m going to throw the code on the discord so that you can steal it for your homework.” 😂
@keyboardcrash38
@keyboardcrash38 2 жыл бұрын
Javid is real mega gigachad
@Jkauppa
@Jkauppa 2 жыл бұрын
about the plane-ray engine, if you have upright view point from the player only, ie, upright planes, then you can use the 2d dda grid, to get the world-vertical-line 2.5d general purpose 3d ray caster, but if you only use the plane-rays with z-buffer (both versions) and entity sphere/ellipse bounding boxes, then you get an all-view-points tilt camera 3d-engine, assuming n-entities
@Jkauppa
@Jkauppa 2 жыл бұрын
try cube map global illumination plane-ray casting (6x pyramid cameras udlrbf-directions per pixel)
@Jkauppa
@Jkauppa 2 жыл бұрын
try this simple 3d (or 2d top-down): entity sphere boundary volume sorting (all entities kinda instanced), per-pixel ray casting intersection/culling per sphere boundary volumes (sorted closest entity first about in order draw), then same point sphere distance math for triangles (also any level of sphere boundary volume hierarchies, but it should be very simple & fast with entity single level boundary volume alone, maybe each level/arena/checkpoint with their own entity set, so that bloat is limited)
@valtsuhw
@valtsuhw 2 жыл бұрын
Hello, good content. A video about probabilities, random number generation / content generation would be great. Thanks!
@javidx9
@javidx9 2 жыл бұрын
Check out my Programming The Universe video, I create an entire universe out of random numbers
@minijimi
@minijimi 2 жыл бұрын
Good Job Mr. Lone Coder.
@miladhashemzadeh5626
@miladhashemzadeh5626 2 жыл бұрын
King of magician in programmers world please accept my Endless respect
@ryanlockhart5328
@ryanlockhart5328 2 жыл бұрын
would it not be more efficient to store a "signed" number as a struct containing a bool and an unsigned integer? then use logic to determine if we should swap the sign
@javidx9
@javidx9 2 жыл бұрын
The "then use logic" part of your question answers itself regarding efficiency 🙂
@marcoottaviano527
@marcoottaviano527 2 жыл бұрын
Hello David, a bit of an off topic for the video and the channel maybe, but given your coding experience, I'm curious to know what do you think of the functional paradigm? A lot of people (particularly in academia) think it's the "last programming paradigm" and will replace OO. Others think it'll only complement it.
@Humble_Electronic_Musician
@Humble_Electronic_Musician 2 жыл бұрын
Thank you so much for the great content you're putting out. God bless!
@StGSteve
@StGSteve 2 жыл бұрын
Thank you for your hard work!
@DM-qm5sc
@DM-qm5sc 2 жыл бұрын
OH MY HE STILL EXISTS!
@RicoElectrico
@RicoElectrico 2 жыл бұрын
Wish C had widely adopted standard for fixed point and saturation arithmetic.
@Nunya58294
@Nunya58294 2 жыл бұрын
I love C.... But ended up going back to Python haha
@murilo_dev
@murilo_dev Ай бұрын
Thank you very much for this video.
@CyprienMANDA
@CyprienMANDA 2 жыл бұрын
I love how are you teaching I really appreciate it and I’d like to be taught from you how can I create a calculator gui in c++ like wxWidgets by using the empty windows desktop app. Thank you so much, Sr. You’re my favory
@bubuche1987
@bubuche1987 11 ай бұрын
I think that everyone had this idea before me but ... I think I have a way to do the multiplication without needing a bigger type. Note that the following should work for 16_16, 2_30 or any other distribution, and should work for bigger and smaller types. Let's assume we store things on 32bits. We want to multiply X and Y. Let's say Mx represents the 16 most significant bits (followed by 16 zeros), Lx the 16 least significant bits, My the 16 msb of Y (followed by 16 zeros) and Ly the 16 lsb of Y. X = Mx + Lx Y = My + Ly X * Y = (Mx + Lx) * (My + Ly) = MxMy + MxLy + LxMy + LxLy Now we have 4 multiplications but each component have only 16 bits with information. We can shift them so they occupy the 16lsb before the multiplication. I didn't find (yet) an equivalent method for division.
@Adomas_B
@Adomas_B 2 жыл бұрын
That vimto can probably has its own ecosystem inside of it by now
@__hannibaalbarca__
@__hannibaalbarca__ Жыл бұрын
I m working for library of Real Number infinitesimal small and big with SIMD and without SIMD; Without looking how CS and Architect doing it; i use only my mathematical package and basic of C/C++.
@footballCartoon91
@footballCartoon91 2 жыл бұрын
@26:23 I always got compiling error when trying to declare a static function.. "a static .. must be relative to a specific object" from this video you are using a specific object congratulations
@coderoyalty
@coderoyalty 2 жыл бұрын
Long time pal
@trashinGame
@trashinGame 2 жыл бұрын
the man is back!
@DAVIDGREGORYKERR
@DAVIDGREGORYKERR Жыл бұрын
Fixed Point Numbers are very useful if you are writing a DSP filter.
@yonis9120
@yonis9120 2 жыл бұрын
Yayyyyyyyy he’s backkkkkkk
@starc0w
@starc0w 2 жыл бұрын
Thank you so much!👍
@alexanderramirez158
@alexanderramirez158 2 жыл бұрын
would you consider any videos on SDL2? love the content!
@javidx9
@javidx9 2 жыл бұрын
Thanks! It's unlikely since I have my own graphics interface that I prefer to use. Nothing wrong with SDL2, just not for me.
@alexanderramirez158
@alexanderramirez158 2 жыл бұрын
@@javidx9 makes sense! thank you for the reply, im starstruck.
@mrmrcoderkid
@mrmrcoderkid 2 жыл бұрын
still patiently waiting for olc codejam 2021 showcase
@Unit_00
@Unit_00 2 жыл бұрын
I love fixed points, the simplicity of the concept is really cool for me. Every time I have the excuse to use them in a project I gladly do so. I wish they were supported as native types in programming languages instead of having to set them up. Right now I'm using them for an open world platformer where there are no load screens so the coordinates for the player character can get very large. Basically I don't want that the further away from (0,0) the player is, the less precise float gets, so this might introduce wacky movement glitches that only happen in certain areas of the world.
@MinecraftWitaminaPL
@MinecraftWitaminaPL 2 жыл бұрын
Yes. In minecraft there is the same problem. When you are on the edge of world. You are moving like 1 meter per free second. It looks like you have 1FPS.
@MinecraftWitaminaPL
@MinecraftWitaminaPL 2 жыл бұрын
I also would like to have fixed point numbers as native.
@sweettea-hv1ls
@sweettea-hv1ls 3 ай бұрын
@@MinecraftWitaminaPL Isn't Minecraft reset transform position every time it gets overflown like every other games?
@MinecraftWitaminaPL
@MinecraftWitaminaPL 3 ай бұрын
@@Unit_00 I just think Minecraft is good example because the world have almost no boundaries and you can use tp command to see the effect
@tw7522
@tw7522 2 жыл бұрын
Very nice. If you'd convert T value to a private member it would be perfect as far as I'm concerned.
@bitw1se
@bitw1se 2 жыл бұрын
What's the issue with having it public?
@laureven
@laureven 2 жыл бұрын
UHU :) ... always a pleasure to watch Your videos. Regards
@TheTopHatCat
@TheTopHatCat 2 жыл бұрын
May you cover casting at some point? I feel that it's a bit of a strange and foreign subject to me when I try to work with this language.
@activex7327
@activex7327 2 жыл бұрын
Can you do a video on floating point? That would nicely complement this video.
@GamerPro-nw5lf
@GamerPro-nw5lf 2 жыл бұрын
Hello friend. I was interested in modifying the textures for a ps2 game, The Getaway: Black Monday. Well, according to what I researched to be able to do this, I would have to extract the textures from the game and then modify the texture, but there are no videos explaining how to get the extracted and modified texture and put it in the game, importing the modified texture into the game . Well, I saw a comment on a video that the 010 editor, this program, is used to import the texture that was exported and modified. Well is this true? If so, could you bring a tutorial explaining how to import the texture of the ps2 game that was exported to be modified? I could even pay money for a tutorial of yours explaining how to do this with the game I wanted to modify.
@Lado93
@Lado93 Жыл бұрын
i just still dont get the conversion from float to fixed gosh
@minirop
@minirop 2 жыл бұрын
Instead of using user-defined literal, I would have went with simply overloading operator* between fixed and double or even between 2 fixed and let the compiler implicitly convert the double
@GameBacardi
@GameBacardi 2 жыл бұрын
Nice! Thank you
@mohammadmahdifarnia5358
@mohammadmahdifarnia5358 2 жыл бұрын
Thank U very much 🙏🙏🙏🙏
@fengshengteoh3054
@fengshengteoh3054 2 жыл бұрын
Hi hi Dear Javidx9 I m sheng here come form Malaysia, you may don’t know me.but I super super super love your channel. I m a dental technician.in this few year I want to push myself in dental line better.After it I try to learn c# and c++ to improve myself.i m try to do a small CAD software to help myself. Question 🙋‍♂️ But I have no idea where and how to start a CAD Software,May you giving me some advance?? Thank you so much,but don’t worry just reply if you are truly free.
@MinecraftWitaminaPL
@MinecraftWitaminaPL 2 жыл бұрын
To be honest i think fixed numbers are better than floating point numbers. For example if there is a big float number. For example sth like 4.000.000.000.000 than the next number is 4.000.000.000.004 and where there is for example 4 the mext number is 4,0000000000000000525 or sth like that. But when we are using fixed point numbers there is no such thing like that. You just can set for example 4 bits for the fractional part. For example 4. Next number is 4.0625 next 4.1250. For me there is more consistency.
@Yougocean
@Yougocean 2 жыл бұрын
I have done those steps
@justacherryontop6538
@justacherryontop6538 2 жыл бұрын
can you please make a video on how to access low level hardware without including any library. like accessing sound card, graphic card to write frame directly to frame buffer
@giornikitop5373
@giornikitop5373 2 жыл бұрын
virtually impossible. any modern os will not allow you to do that, only a driver can directly access hardware. any other program must use an appopriate API like winapi, sdl, directx etc, which in turn will talk to the driver and do the operations. now, if you want to learn how to create a driver for a device, that's a whole different huge can of worms. but you will still rely on the os api's for other things you might need like memory allocation, threads, interrupts and stuff like that. stay with the os's API's.
@javidx9
@javidx9 2 жыл бұрын
It's quite difficult without actually writing an OS these days. Also many hardware drivers are still proprietary. If course it is possible, but very hard on a modern day desktop.
@justacherryontop6538
@justacherryontop6538 2 жыл бұрын
@@javidx9 I understand, thanks for the replay😊 but, you said you will be explaining in the future--> kzbin.info/www/bejne/qpjEnpurhtOCoa8 at 6:45😁🤓
@abacaabaca8131
@abacaabaca8131 2 жыл бұрын
​@@giornikitop5373 from watching ben eater videos, let me try to answer this in theory i could say in general you need to reverse engineer the source code of the driver.. you ask yourself where is the virtual memory address (page memory address) and then you do some mathematic to know where is the pyhsical address of the hardware.. then figure out how many possible operation the output device/hardware can do.. if you have oscilloscope you could try to reverse engineer from there.. first there is a some sort of initial buffer that tells you what manufacturer of the device is and etc etc after that you need to distinguish the opcodes, data, and addresses.. for example if the graphic card can only do things like read and write so we can figure out its enumeration constants.. maybe in between 0 and 1.. and then if you know that, you can basically find a C++ compiler for a particular cpu.. although i did nt do this yet.. i really hope i can do this.. probably it is much more work than this i dont know
@giornikitop5373
@giornikitop5373 2 жыл бұрын
@@abacaabaca8131 um, no. source code does provide lots of info, but there are always binary blobs/firmware that are proprietary and thus, unknown. if there are gpu drivers that are 100% open source, then ok. now, for something simple, as @Just A cherry OnTop asked, like accessing the framebuffer, that might be enough. I haven't watched bean eater videos but i'm guessing he reversed some simple device or cpu, more or less already known, like 6502, z80 etc. reversing a modern gpu from zero is a whole different level of pain. let me put it this way: unless you're a gpu engineer of that lvl, know what you're looking for and have high-tech equipment, your chances are practicaly zero.
@TariqYasiinProd
@TariqYasiinProd 2 жыл бұрын
Please teach us about Quake's fast reverse sqrt algorithm
@mpoadmin2978
@mpoadmin2978 Жыл бұрын
OMG can you please write a book on c++ or make a very thorough lesson to modern c++?
@mpoadmin2978
@mpoadmin2978 Жыл бұрын
a lot of these tutorials would be AMAZING content for books!
@1777bond
@1777bond 2 жыл бұрын
nice video!
@rosen8757
@rosen8757 2 жыл бұрын
A common use for fixed point is multiplayer games where the game physics have to be deterministic between users.
@rsa5991
@rsa5991 2 жыл бұрын
But floats are deterministic too.
@rosen8757
@rosen8757 2 жыл бұрын
@@rsa5991 on one cpu yes, but across several the FPU actually behaves differently sometimes. If I remember correctly the game Trackmania uses fixed point because of this.
@sweettea-hv1ls
@sweettea-hv1ls 9 ай бұрын
@@rosen8757 Well there is IEEE 754-2008 which can be enabled in compiler and u can use floats deterministically
@jahjae
@jahjae 2 жыл бұрын
Thanks
@quincy1048
@quincy1048 2 жыл бұрын
Discord rookie here...You said...you was putting the code on the discord...but alas I couldn't find it. Yea not sure if I am looking in the right place...so anybody got any tips on finding it. Just looking to commit these concepts to permenant storage by storing th code example.
@quincy1048
@quincy1048 2 жыл бұрын
I got someone on the discord chat to be kind enough to give me a link so got it, thank you.
@icedude_907
@icedude_907 2 жыл бұрын
I struggle to think of a good use for IEEE floats... ever. High levels of precision: no, rounding errors. Large numbers: not really, rounding errors Scientific computing: no, as above Speed: no, software is slow, hardware is slower than fixed and massively bulks up the math unit. Slight rounding issues have been present per manufacturer. Aside from being convenient to use (excl a broken ==) due to compiler support I struggle to think of uses. It just feels like a case of everyone doing it and having to be compatible. Maybe 3D rendering, but it high precision is still hard to do as math operations (like matrix multiplication) destroy and lead to funny bugs / clipping
@田淞煜
@田淞煜 2 жыл бұрын
I love Basics
@HalValla01
@HalValla01 2 жыл бұрын
8:42 Sorry but I have to point this out......1/6??
@zyghom
@zyghom 2 жыл бұрын
unbelievable
@justanormalperson
@justanormalperson 2 жыл бұрын
nice
@skope2055
@skope2055 2 жыл бұрын
awesome
@empireempire3545
@empireempire3545 2 жыл бұрын
Now how do i printf these... :D
@benhetland576
@benhetland576 2 жыл бұрын
In C++ you can instead write a custom _ostream& operator
@empireempire3545
@empireempire3545 2 жыл бұрын
@@benhetland576 I am not looking for easiest. If i wanted easiest, i would program in java and python. I know i can overload operators. IOstreams are horribly slow, annoying to work with and to format. This is why C++ 20 will have libfmt. In the meantime i prefer to stay with c style io, and afaik you CAN define custom symbols for them - even if it is not trivial.
@benhetland576
@benhetland576 2 жыл бұрын
@@empireempire3545 Yes, I believe GNU has an (non-standard) extension API for this, but that might count as too easy too? OK then, go ahead and write your own _printf_ implementation :-)
@bitw1se
@bitw1se 2 жыл бұрын
@@benhetland576 You can't do operator overloading in C, so you would have to write a function that accepts the fixed struct and returns a double.
@bitw1se
@bitw1se 2 жыл бұрын
@@empireempire3545 iostreams are not necessarily slow. It depends on how you use them. The API design might be bad in that regard, since there are a few traps that can slow down your program.
@smartito_97
@smartito_97 2 жыл бұрын
Hi david!! lets play a video about IEEE 754
@akkudakkupl
@akkudakkupl 2 жыл бұрын
In the end it wasn't 4.4 but 8.8 ;-)
@Nunya58294
@Nunya58294 2 жыл бұрын
Javid!!!!!
Quirky Quad Trees Part 2: Dynamic Objects In Trees
44:13
javidx9
Рет қаралды 42 М.
Back To Basics: C++ Containers
31:41
javidx9
Рет қаралды 190 М.
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 700 М.
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
Floating Point Numbers (Part1: Fp vs Fixed) - Computerphile
15:41
Computerphile
Рет қаралды 161 М.
How Floating-Point Numbers Are Represented
9:56
Spanning Tree
Рет қаралды 37 М.
Where Has Javidx9 Gone? (and more important things)
8:58
javidx9
Рет қаралды 44 М.
The Dome Paradox: A Loophole in Newton's Laws
22:59
Up and Atom
Рет қаралды 974 М.
Fixed Point Maths Explained - Retro Programming
17:31
NCOT Technology
Рет қаралды 3,6 М.
Why Computers Screw up Floating Point Math
12:10
Mental Outlaw
Рет қаралды 338 М.
Fixed Point Decimal Numbers - Including Fixed Point Arithmetic
11:24
Stop Recommending Clean Code
27:05
ThePrimeTime
Рет қаралды 555 М.
Floating Point Numbers - Computerphile
9:16
Computerphile
Рет қаралды 2,4 МЛН
Fixed-point math is better than floating point (sometimes)
1:32:06
Low Byte Productions
Рет қаралды 18 М.
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 700 М.