1st Edition

Floating Point Numerics for Games and Simulations

By Nima Badizadegan Copyright 2025
230 Pages 61 B/W Illustrations
by CRC Press

230 Pages 61 B/W Illustrations
by CRC Press

230 Pages 61 B/W Illustrations
by CRC Press

Floating point is ubiquitous in computers, where it is the default way to represent non-integer numbers. However, few people understand it. We all see weird behavior sometimes, and many programmers treat it as a mystical and imprecise system of math that just works until it sometimes doesn’t. We hear that we shouldn’t trust floating point with money, we know that 0.1 + 0.2 does not equal 0.3, and... Read more

Preface

List of Figures

List of Tables

List of Algorithms

1    Computing with Numbers

1.1      Between the Integers

1.2      Representing the Real Numbers

1.3      Properties of Number Formats

1.4      Fixed-Point Arithmetic

1.5      Decoupling Precision from Magnitude

2    Numbers in Floating Point

2.1      Extending the Real Numbers

2.2      Binary Scientific Notation

2.3      Floating Point Bit Layouts

2.4      Zeros and Infinities

2.5      Subnormal Numbers

2.6      NaNs (Not-a-Number)

2.7      Other Floating-Point Formats

3    Sources of Error

3.1      Rounding and Rounding Modes

3.2      Errors and Exceptions

3.3      The Inexact (IX) Exception

3.4      Invalid Operations (IO) and Division by Zero (DZ)

3.5      Overflow (OF) and Underflow (UF)

3.6      Exceptions and Rounding in Processors

4   The Basic Arithmetic Operations

4.1      Multiplication

4.2      Division

4.3      Addition and Subtraction

4.4      Square Root

4.5      Fused Multiply Add (FMA)

4.6      The Algebra of Floating Point

5    Comparing Floating-Point Numbers

5.1      Relative Comparisons

5.2      Minimum and Maximum

5.3      Equality and Epsilons

5.4      Setting Epsilon

5.5      Exceptions in Comparisons

5.6      Regime Comparisons

5.7      Total Ordered Comparison

5.8      Interactions between Comparisons

6   Conversion to and from Floating Point

6.1      Rounding to Integers

6.2      Narrowing and Widening Formats

6.3      Integer to Float Conversion

6.4      Float to Integer Conversion

6.5      String to Float

6.6      Float to String

6.7      Exactness of Decimals in Floating Point

6.8      Bit Casting Floating-Point Numbers

7    Numerical Operations

7.1      Remainder and Modulus Operations

7.2      Exponentials and Logarithms

7.3      Powers and Roots

7.4      Reciprocal Square Root

7.5      Trigonometric Functions

7.6      Hyperbolic Functions

7.7      Statistical Functions

8   Bitwise Manipulations

8.1      Exponent Manipulation

8.2      Sign Bit Manipulation

8.3      Iterators

8.4      NaN Boxing

9   Working with Error in Floating Point

9.1      Algebra for Accuracy

9.2      Changes of Units

9.3      Double-word Arithmetic

9.4      Interval Arithmetic

9.5      Error Analysis

9.6      Avoiding Invalid Operations

9.7      Fast Math Compiler Options

10 Function Approximation

10.1 Accuracy of Approximations

10.2 Polynomial Approximations

10.3   Newton-Raphson and Iterative Methods

10.4   Lookup Tables and Interpolation

10.5   Comparison of Math Libraries

10.6   Floating Point Bit Hacks

11  Geometry in Floating Point

11.1   Polygons and Transforms

11.2   Splines

11.3   B´ezier Curves and Surfaces

11.4   B-Splines and NURBS

11.5   Faraway Objects and Floating Point

11.6   Intersection Finding and Collision Detection

11.7   The Gilbert-Johnson-Keerthi Algorithm

12 Numerical Integration

12.1   Simulation Accuracy and Error

12.2   Euler Integration

12.3   Adding Energy Conservation to Euler

12.4   Leapfrog Integration and Velocity Verlet

12.5   Predictor-Corrector Methods

12.6   Runge-Kutta Methods

12.7   Direct Calculation of Trajectories

12.8   Comparison of Numerical Integrators

Bibliography

Index

Biography

Nima Badizadegan is an engineer who works at the intersection of computer systems and mathematics. His past experience includes work at Google and on Wall Street, as well as being a consultant and startup founder. Badizadegan has several publications in the fields of simulation and computer arithmetic and is the inventor of over 10 patents. He is a member of the IEEE and ACM and contributes to the IEEE 754 floating point standard. He is the author of the popular technical blog Speculative Branches (https://specbranch.com), where he writes about computer systems, software engineering, and math.