liveBook · Manning

Integer wraparound

Integer wraparound is arithmetic behavior in which an out-of-range fixed-width integer result cycles or is reduced modulo the type’s representable range.

How 4 Manning books explain it

Code Like a Pro in Rust

How it is used
Uses explicit wrapping to express modular arithmetic and avoid unintended differences between test and production builds.
How deep it goes
Demonstrates primitive and generic wrapping operations, contrasting them with checked arithmetic and build-profile overflow behavior.
Examples
Shows unsigned boundary operations and an `i64` property test that first fails on overflow, then passes with explicit wrapping.
What you can do after
Apply wrapping arithmetic using Rust primitive methods, `Wrapping`, or `num_traits::WrappingAdd` for generic addition.

Read how Code Like a Pro in Rust explains integer wraparound →

Modern C

Unsigned wraparound is the reduction of an out-of-range unsigned arithmetic result into the representable range by modular reduction.

How it is used
Explains modular behavior in unsigned arithmetic, size_t calculations, clock-style remainders, and loop-index safety.
How deep it goes
Defines reduction modulo SIZE_MAX + 1 and works through boundary examples, but does not develop implementation internals.
Examples
Uses clock arithmetic, minute remainders, SIZE_MAX + 1, 0 - 1, and explicit loop-index checks.
What you can do after
Apply it via C unsigned types while recognizing boundary values and guarding loop increments against unintended wraparound.

Read how Modern C explains integer wraparound →

Go in Action, Second Edition

Integer wraparound is the behavior in which arithmetic outside an integer type's representable range produces a value obtained by cycling through its fixed-width bit representation.

How it is used
Explains integer-type choices and safer function parameter design when values may cross signed or unsigned boundaries.
How deep it goes
Demonstrates bit-level boundary behavior and conversion consequences, then stops at validation guidance rather than broader arithmetic internals.
Examples
Uses uint64 subtraction, an unsigned-only function, negative literals, converted negative values, and explicit error checking.
What you can do after
Diagnose unexpected large unsigned values and design signed, validated function inputs that expose negative-value errors.

Read how Go in Action, Second Edition explains integer wraparound →

Systems Programming with Zig

Wrapping arithmetic is integer arithmetic whose result wraps modulo the destination type's representable range on overflow.

How it is used
Implements CHIP-8 register and address instructions that require arithmetic to wrap on overflow.
How deep it goes
Defines wrapping operators, contrasts ordinary addition's debug-mode panic, and describes overflow-reporting builtins.
Examples
Uses opcode 7XKK for wrapping register addition and BMMM and FX1E for wrapping address additions.
What you can do after
Apply Zig's wrapping operators to implement CHIP-8 arithmetic that wraps on overflow.

Read how Systems Programming with Zig explains integer wraparound →

Related concepts

Questions about integer wraparound

What is integer wraparound?

Integer wraparound is arithmetic behavior in which an out-of-range fixed-width integer result cycles or is reduced modulo the type’s representable range.

Which Manning books explain integer wraparound?

Code Like a Pro in Rust, Modern C, Go in Action, Second Edition and Systems Programming with Zig.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.