Skip to content

alter_fp_rounding_mode Is Not Panic Safe #7356

Closed

Description

@tustvold

Describe the bug

alter_fp_rounding_mode makes use of fesetround in order to alter the rounding mode on various architectures

let current = fegetround();
fesetround(if UPPER { FE_UPWARD } else { FE_DOWNWARD });
let result = operation(lhs, rhs);
fesetround(current);
result

Unfortunately if operation panics, fesetround will never revert the rounding mode. Drop would be a more reliable way around this, although there are still situations where Drop may not be called

To Reproduce

No response

Expected behavior

Ideally we wouldn't modify global thread-local state at all, but I'm not sure if this can be avoided

Additional context

No response

Activity

  1. added a commit that references this issue on Oct 18, 2026
    61c3472
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions