Skip to content

[DirectX] frexp() disregards sign #9155

Open

Description

frexp() always returns a positive mantissa, even for negative input. In this example, the first float argument at output line 7 should be -0.5 rather than 0.5.

Activity

  1. added
    bug
    needs-triage
    on Nov 20, 2026
  2. damyanp commented on Nov 20, 2026

    @damyanp
    Member

    Unfortunately I think that this behavior may well be baked in to DXBC and DXIL, so we need to be careful about fixing it. See #7737 that explicitly adds an abs and notes the difference between HLSL and C++'s implementations of frexp.

  3. danbrown-amd commented on Nov 23, 2026

    @danbrown-amd
    ContributorAuthor

    Note however that the SPIR-V translation (to OpExtInst ... FrexpStruct, with no absolute value operation) is defined to agree with the C++ standard, so there is an inconsistency. (I do recognize that fixing this would break some existing code. I submitted this issue primarily to have something to point to as an XFAIL reason in LLVM's offload test suite.)

  4. llvm-beanz commented on Nov 25, 2026

    @llvm-beanz
    Collaborator

    I almost think the right fix here (at least temporarily) is that the SPIRV code generation in DXC insert an abs call on the input to frexp. That would make the compilers compatible and consistent.

    Separately TC57 should decide if the behavior should change to align with C/C++.

  5. danbrown-amd commented on Nov 25, 2026

    @danbrown-amd
    ContributorAuthor

    If it's worth making a breaking change, why not make them compatible in the direction that 1) agrees with the C++ standard and 2) preserves more information? The programmer can get the absolute value easily enough if that's what's desired. (Note that I'm a compiler guy rather than a graphics guy, so maybe I'm missing something here. Is it just that DXIL is most often targeted?)

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

    bugneeds-triage

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions