liveBook · Manning

Narrowing conversion

A narrowing conversion converts a value to a type with a smaller representable range or lower precision, potentially losing information.

How 3 Manning books explain it

100 Java Mistakes and How to Avoid Them

A narrowing conversion converts a value to a type with a smaller representable range or less general numeric domain, potentially discarding information.

How it is used
Explains how Java casts and compound assignments can discard numeric information and cause incorrect program behavior.
How deep it goes
Works through overflow, bit loss, widening order, and analyzer limits, then stops short of a general numeric-conversion taxonomy.
Examples
Uses file lengths, character multiplication, negative bytes, and unsigned right shifts as concrete failure cases.
What you can do after
Diagnose unsafe casts and compound assignments, then replace them with range checks, exact conversion, or wider types.

Read how 100 Java Mistakes and How to Avoid Them explains narrowing conversion →

Modern C

A narrowing conversion is a conversion to a type whose representable range or precision cannot preserve all values of the source type.

How it is used
Warns against value loss in assignments and mixed-type arithmetic.
How deep it goes
Explains fitting values, overflow-related results, precision loss, and mixed signedness, but defers broader type-rule details.
Examples
Uses integer assignments, floating-point expressions, and signed-versus-unsigned comparisons to expose harmless and dangerous conversions.
What you can do after
Evaluate C conversions for representability, information loss, precision loss, and mixed signedness.

Read how Modern C explains narrowing conversion →

Modern C, Third Edition

A narrowing conversion is a conversion to a type that represents a smaller range or less precise set of values than the source type.

How it is used
Uses implicit conversions to evaluate whether assignments and mixed-type operations preserve values safely.
How deep it goes
Explains value-fit checks, literal-specific behavior, unsigned modular conversion, and precision loss in mixed arithmetic.
Examples
Uses signed and unsigned assignments, hexadecimal and decimal minimum values, and mixed integer-floating-point expressions.
What you can do after
Evaluate whether conversions preserve values and identify cases that may lose range, precision, or information.

Read how Modern C, Third Edition explains narrowing conversion →

Related concepts

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.