Fix display of double values

This commit is contained in:
baldurk
2020-06-08 14:12:11 +01:00
parent 84da098a00
commit 6f950afea7
2 changed files with 22 additions and 5 deletions
@@ -267,7 +267,7 @@ void ParseConstant(const LLVMBC::BlockOrRecord &constant, const Type *&curType,
else if(curType->bitWidth == 32)
memcpy(&v.val.fv[0], &constant.ops[0], sizeof(float));
else
memcpy(&v.val.dv[0], &constant.ops[0], sizeof(float));
memcpy(&v.val.dv[0], &constant.ops[0], sizeof(double));
addValue(v);
}
else if(IS_KNOWN(constant.id, ConstantsRecord::STRING))
@@ -22,6 +22,8 @@
* THE SOFTWARE.
******************************************************************************/
#include <math.h>
#include <stdlib.h>
#include "common/formatting.h"
#include "dxil_bytecode.h"
@@ -808,20 +810,35 @@ rdcstr Value::toString() const
{
if(type->scalarType == Type::Float)
{
double orig;
if(type->bitWidth > 32)
ret += StringFormat::Fmt("%le", val.dv[0]);
orig = val.dv[0];
else
ret += StringFormat::Fmt("%e", val.fv[0]);
orig = val.fv[0];
// NaNs/infs are printed as hex to ensure we don't lose bits
if(!isnan(orig) && !isinf(orig))
{
// check we can reparse precisely a float-formatted string. Otherwise we print as hex
rdcstr flt = StringFormat::Fmt("%.6le", orig);
double reparse = strtod(flt.begin(), NULL);
if(orig == reparse)
return ret + flt;
}
ret += StringFormat::Fmt("0x%llX", orig);
}
else if(type->scalarType == Type::Int)
{
// LLVM seems to always interpret these as signed? :(
if(type->bitWidth > 32)
ret += StringFormat::Fmt("%lld", val.u64v[0]);
ret += StringFormat::Fmt("%lld", val.s64v[0]);
else if(type->bitWidth == 1)
ret += val.uv[0] ? "true" : "false";
else
ret += StringFormat::Fmt("%d", val.uv[0]);
ret += StringFormat::Fmt("%d", val.iv[0]);
}
}
else if(type->type == Type::Vector)