Skip to content

Commit 43370fb

Browse files
committed
unorm literal implementation now ensures that the value is a proper unorm value (i.e. a value between 0.0 and 1.0, inclusive, which is equal to one of 256 discrete, equidistant values along that spectrum where the first value is 0.0 and the two hundred fifty sixth value is 1.0).
1 parent b4711d4 commit 43370fb

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

N3888_RefImpl/src/drawing.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,9 @@ namespace std {
383383
}
384384

385385
inline double operator "" _unorm(long double value) {
386-
return ::std::max(0.0, ::std::min(1.0, static_cast<double>(value)));
386+
auto result = ::std::max(0.0, ::std::min(1.0, static_cast<double>(value)));
387+
result = ::std::nearbyint(result * 255.0); // We need to ensure it is one of the discrete values between 0 and 255.
388+
return result / 255.0;
387389
}
388390
}
389391
#endif

N3888_RefImpl/src/xdrawing.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
#include <cstdint>
1616
#include <tuple>
1717
#include <mutex>
18+
#include <cmath>
1819

1920
#endif

0 commit comments

Comments
 (0)