File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -262,9 +262,19 @@ inline unsigned char FTOC(float a)
262
262
Note to self: Don't replace this with an inline for quicker conversions
263
263
to int if/when doing so later. */
264
264
265
- int ret = lround (a*256 .f - 0 .5f );
266
- CLAMP (ret, 0 , 255 );
265
+ /* Update: Nevermind the above, minus the you're all idiots part.
266
+
267
+ > test <- seq(0,1,0.0000001)
268
+ > testRound <- sapply(test, function(x) round(x*256 - 0.5))
269
+ > testInt <- sapply(test, function(x) as.integer(x*256))
270
+ > all(testRound == testInt)
271
+ [1] TRUE
267
272
273
+ Tested using double precision floating point numbers. I'm so disgusted
274
+ right now. - Mina */
275
+
276
+ int ret = static_cast <int >(a*256 .f );
277
+ CLAMP (ret, 0 , 255 );
268
278
return static_cast <unsigned char >(ret);
269
279
}
270
280
You can’t perform that action at this time.
0 commit comments