DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

[DirectX] frexp() disregards sign

Open danbrown-amd opened this issue 2 weeks ago • 2 comments

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.

danbrown-amd avatar Nov 20 '26 03:11 danbrown-amd

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.

damyanp avatar Nov 20 '26 17:11 damyanp

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.)

danbrown-amd avatar Nov 23 '26 21:11 danbrown-amd