Skip to main content

narrow_to_signed32

Function narrow_to_signed32 

Source
pub fn narrow_to_signed32(v: i64) -> i64
Expand description

The integer view of a stored integer: keep the low 32 bits and read them as signed.

It neither clamps nor saturates: a value above i32::MAX came from an unsigned token, and its bit pattern is reinterpreted. Within INT_RANGE the only inputs that move are those above i32::MAX.

use pdfrum_object::narrow_to_signed32;

assert_eq!(narrow_to_signed32(1245), 1245);
assert_eq!(narrow_to_signed32(-99), -99);
assert_eq!(narrow_to_signed32(4_294_967_295), -1);
assert_eq!(narrow_to_signed32(2_147_483_648), -2_147_483_648);