Skip to content

Float to int32 conversion may cause overflow #872

Description

@jdemel

There's an issue in volk_32f_s32f_convert_32i.

The intended logic is:

  1. scale the input float value by scalar
  2. clamp float value to 32bit integer range [-2147483648, 2147483647], or [-2147483648, 2147483648)
  3. Convert to int.

Unfortunately, the operation:

float value = 2147483648.0f - 1.0f;

does not result in 2147483647.0f, but 2147483648.0f since the next lower float representable number is 2147483520.0f. Thus,

int32_t result = (int32_t) 2147483648.0f - 1.0f;

results in -2147483648, aka overflow.

It may be possible to clamp the float value to 2147483520.0f but a number such as 6167483520.0f would then result in 2147483520 instead of 2147483647 which would've been the expected value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions