Skip to content

Commit 2faa10b

Browse files
author
Sam Feeney
committed
Removed any rounding from the FTOC function. See comment for details.
1 parent a559386 commit 2faa10b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/RageTypes.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,19 @@ inline unsigned char FTOC(float a)
262262
Note to self: Don't replace this with an inline for quicker conversions
263263
to int if/when doing so later. */
264264

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
267272
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);
268278
return static_cast<unsigned char>(ret);
269279
}
270280

0 commit comments

Comments
 (0)