Skip to content

Commit 0bfb701

Browse files
committed
[css-color-4] Math.pow with negative base and non-integer exponent is NaN
1 parent 3ca61f4 commit 0bfb701

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

css-color-4/conversions.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function lin_sRGB(RGB) {
88
// convert an array of sRGB values in the range 0.0 - 1.0
99
// to linear light (un-companded) form.
1010
// https://en.wikipedia.org/wiki/SRGB
11+
// TODO for negative values, extend linear portion on reflection of axis, then add pow below that
1112
return RGB.map(function (val) {
1213
if (val < 0.04045) {
1314
return val / 12.92;
@@ -21,6 +22,7 @@ function gam_sRGB(RGB) {
2122
// convert an array of linear-light sRGB values in the range 0.0-1.0
2223
// to gamma corrected form
2324
// https://en.wikipedia.org/wiki/SRGB
25+
// TODO for negative values, extend linear portion on reflection of axis, then add pow below that
2426
return RGB.map(function (val) {
2527
if (val > 0.0031308) {
2628
return 1.055 * Math.pow(val, 1/2.4) - 0.055;
@@ -104,6 +106,7 @@ function lin_ProPhoto(RGB) {
104106
// convert an array of prophoto-rgb values in the range 0.0 - 1.0
105107
// to linear light (un-companded) form.
106108
// Transfer curve is gamma 1.8 with a small linear portion
109+
// TODO for negative values, extend linear portion on reflection of axis, then add pow below that
107110
return RGB.map(function (val) {
108111
if (val < 0.031248) {
109112
return val / 16;
@@ -117,6 +120,7 @@ function gam_ProPhoto(RGB) {
117120
// convert an array of linear-light prophoto-rgb in the range 0.0-1.0
118121
// to gamma corrected form
119122
// Transfer curve is gamma 1.8 with a small linear portion
123+
// TODO for negative values, extend linear portion on reflection of axis, then add pow below that
120124
return RGB.map(function (val) {
121125
if (val > 0.001953) {
122126
return Math.pow(val, 1/1.8);
@@ -155,16 +159,18 @@ function XYZ_to_lin_ProPhoto(XYZ) {
155159
function lin_a98rgb(RGB) {
156160
// convert an array of a98-rgb values in the range 0.0 - 1.0
157161
// to linear light (un-companded) form.
162+
// negative values are also now accepted
158163
return RGB.map(function (val) {
159-
return Math.pow(val, 563/256);
164+
return Math.pow(Math.abs(val), 563/256)*Math.sign(val);
160165
});
161166
}
162167

163168
function gam_a98rgb(RGB) {
164169
// convert an array of linear-light a98-rgb in the range 0.0-1.0
165170
// to gamma corrected form
171+
// negative values are also now accepted
166172
return RGB.map(function (val) {
167-
return Math.pow(val, 256/563);
173+
return Math.pow(Math.abs(val), 256/563)*Math.sign(val);
168174
});
169175
}
170176

0 commit comments

Comments
 (0)