forked from microsoft/DirectXShaderCompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial proposal for hlsl::numeric_limits (#2)
This seeks to remove the HLSL `#INF` syntax in favor of a more C++-like hlsl::numeric_limits construct.
- Loading branch information
1 parent
5d5298a
commit 520086d
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Numeric Constants | ||
|
||
* Proposal: [0003](0003-numeric-constants.md) | ||
* Author(s): [Chris Bieneman](https://github.com/llvm-beanz) | ||
* Sponsor: [Chris Bieneman](https://github.com/llvm-beanz) | ||
* Status: **Under Consideration** | ||
* Planned Version: 202x | ||
|
||
## Introduction | ||
|
||
A new C++ STL-styled numeric constants interface will enable migrating off older | ||
inconsistent language features and make cleaner more concise code. | ||
|
||
## Motivation | ||
|
||
The HLSL Infinity constant syntax violates C token rules by using the `#` | ||
character, and is not consistent with C or C++ language styling. This causes | ||
technical challenges by using reserved preprocessor tokens, but also makes the | ||
feature foreign and less approachable in a C-like language. | ||
|
||
## Proposed solution | ||
|
||
Starting with adoption the `#INF` token becomes unsupported preferring instead a | ||
new library class modeled after the C++ `std::numeric_limits` classes. Below is | ||
the proposed interface for the `hlsl::numeric_limits` class: | ||
|
||
```c++ | ||
template<typename Ty> | ||
class numeric_limits { | ||
public: | ||
static Ty min(); | ||
static Ty max(); | ||
static Ty lowest(); | ||
static Ty denorm_min(); | ||
|
||
// Implement infinity in terms of __builtin_huge_val | ||
static Ty infinity(); | ||
static Ty negative_infinity(); | ||
|
||
static Ty quiet_NaN(); | ||
static Ty signaling_NaN(); | ||
} | ||
``` | ||
This enables a straightforward code transformation from `1.#INF` to | ||
`hlsl::numeric_limits<float>::infinity()`. While the later is more verbose, it | ||
is more clear and provides a more consistent C++ style. |