Fixed Point Maths Explained - Retro Programming

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ส.ค. 2024
  • A video explaining how fixed point maths works and why it is useful on CPUs that have no floating point units.
    A written version of this is available on my website, linked below
    Fixed point maths is a way to deal with decimal numbers, on systems where they don't have the ability to use decimals. The basic concept is to scale all numbers up by a certain amount to remove any decimal parts of the number. Then you can work with whole numbers only, scaling back down when needed.
    What scale you use depends on the range of numbers needed for a particular situation. It can also depend on what the hardware is best at managing. A Z80 CPU for example can work with 16 bit values reasonably easily. And if you’re not trying to do complex accurate scientific calculations, the resolution of your machine’s screen is likely to be a factor as well.
    But if you want a quick one to use, this explanation uses what is called 8.8 fixed numbers. That is a 16 bit value where the upper 8 bits are the whole number and the lower 8 bits the fractional part. With an imaginary binary point in the middle.
    Link to website: docs.ncot.uk/computing-maths/...
    Chapters
    00:17 Maths is hard
    00:56 Floating point maths
    01:45 I have more videos!
    03:53 What we're trying to do
    04:57 Example with money
    06:39 Introducing fixed point maths
    08:28 negative numbers
    10:39 Explaining fixed point
    15:03 Summary
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 13

  • @agnichatian
    @agnichatian 2 ปีที่แล้ว +3

    Fun stuff - subbed. I stumbled upon this as I'm writing some fixed-point for an ATMega328 microcontroller. I'm using "Q15.16" format in this case, in my motor control code. It is way faster than floats, especially when I also approximate the sine function using parabolas. Keep up the good work; will check out what else is on your channel.

  • @arronshutt
    @arronshutt 2 ปีที่แล้ว +1

    Really impressed with the presentation and professional set up, the clear work on squared paper and it's well explained. Definitely heading into a level of explanatory quality that a certain UK university that specialises in computer files might put out :D
    Looking forward to the next coding video :D

    • @ncot_tech
      @ncot_tech  2 ปีที่แล้ว +1

      I may be slightly influenced by a certain computing TH-cam channel, yes.
      Also I'm impressed that TH-cam hasn't eaten your comment this time!

    • @arronshutt
      @arronshutt 2 ปีที่แล้ว +1

      @@ncot_tech I guess that I didn't mention anything contentious to TH-cam like the dislike bu[COMMENT DELETED]

  • @Xalior
    @Xalior 2 ปีที่แล้ว +2

    One minor correction, the screen is 320 pixels across... You're using a mode that only uses 256 pixels across... :-P And that's before we discuss the half-width pixel mode... :-D
    -Dx

    • @ncot_tech
      @ncot_tech  2 ปีที่แล้ว +3

      Agh you crazy hardware designers and “well who says we have to use 8 bits for everything, nine is fine” attitude. It’s thinking like that which gave us the original interleaved speccy ULA modes 😜 Guess we should be thankful you went for regular bitmaps and not bitplanes.

    • @Xalior
      @Xalior 2 ปีที่แล้ว +3

      @@ncot_tech 9bit is a whole one bit better than 8bit, innit.
      -Dx

  • @murators4732
    @murators4732 ปีที่แล้ว

    good one!

  • @jonwest776
    @jonwest776 2 ปีที่แล้ว

    Enjoyed this. Look for the cheats! Look up tables.

  • @benholroyd5221
    @benholroyd5221 11 หลายเดือนก่อน

    To be pedantic representing negative in binary isn't inherently different to decimal. I could write -01011010.
    The computer representation of a negative is different to how we write it. Well it can be, and generally is in practice.

  • @Tabu11211
    @Tabu11211 9 หลายเดือนก่อน

    I want to make a 3D engine that has a ps1 aesthetic so this is essential for me.

  • @bpark10001
    @bpark10001 2 วันที่ผ่านมา

    There is a much simpler scheme (at least in concept). JUST DON'T DO FRACTIONS AT ALL! How to do this & get reasonable accuracy? Up front, declare a small unit that is "smaller than max permitted calculation error" & do all calculations in integer quantities of that unit. In game, you may choose say 1/10000th (or maybe better 1/2^n) of the playing field's dimensions. There is no "fixed point" (unless you consider the one right of the LSB the point). For the money example, let the quantities be in pence.
    When units are dimensionless (such as angle), choose unit that is 1/(2^n) of a full rotation. You simply ignore all carries beyond the nth bit when doing that rotation math.
    This "retro math" should not be retro! For example in computer aided design, integer meth should be used. Floating point math is nothing but trouble. It is very important in CAD that tests for equality work (is the cursor EXACTLY on that "handle"? Is that line & arc "connected"?) Floating point causes quantities that can never be "equal" so the thing you just placed, you can never "grab" again because you can't get the cursor EXACTLY on it. There is also the famous problem of "leakage" in PC Paint app with the paint roller, because line endpoints don't exactly match up. Endpoints of arcs other than 0°/90°/180°270° can't be exactly on line endpoints, if they are specified by center location, radius, & start/end angles. The floating point "solution" is to add "slop" in the calculation (if abs(A - B) < some small number then...). The slop "is small enough unless it is too small". If I move something around in CAD workspace, its (X,Y,Z) parameters change in precision!
    And no, fixed point or integer math CAN & SHOULD be used for trajectory calculations! The problem with floating point is that it has resolution that differs with the distance from zero. If I put (0,0,0) at the center of the sun, what about when I am near Jupiter? Resolution & precision will degrade! Now I have a system with precision that depends upon where I choose (0,0,0).
    Floating point is for quick scientific calculations for those too lazy to properly scale their units.

  • @valentine_puppy
    @valentine_puppy 2 ปีที่แล้ว +1

    How would this apply in creating a world like Nintendo 64 if there was no FPU? What if you had a very fast powerful fixed point DSP instead? Could you make a Mario 64 or better yet the faster Mario kart 64? Thank you for the great video 😀