Skip to content

Commit

Permalink
Output whether value is subnormal in Scalar.toString() (#1388)
Browse files Browse the repository at this point in the history
Helps with debugging subnormal-related test failures.
  • Loading branch information
amaiorano authored May 11, 2022
1 parent 490d2a4 commit 999e396
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/webgpu/util/conversion.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Colors } from '../../common/util/colors.js';
import { assert, TypedArrayBufferView } from '../../common/util/util.js';

import { clamp } from './math.js';
import { clamp, isSubnormalNumber } from './math.js';

/**
* Encodes a JS `number` into a "normalized" (unorm/snorm) integer representation with `bits` bits.
Expand Down Expand Up @@ -502,8 +502,16 @@ export class Scalar {
case Infinity:
case -Infinity:
return Colors.bold(this.value.toString());
default:
return Colors.bold(this.value.toString()) + ' (0x' + this.value.toString(16) + ')';
default: {
const n = this.value as Number;
if (n !== null) {
return (
Colors.bold(this.value.toString()) +
`(0x${this.value.toString(16)}, subnormal: ${isSubnormalNumber(n.valueOf())})`
);
}
return Colors.bold(this.value.toString()) + `(0x${this.value.toString(16)})`;
}
}
}
}
Expand Down

0 comments on commit 999e396

Please sign in to comment.