<< >>
justin = { main feed , music , code , askjf , pubkey };
[ <<< last (older) article | view in index ]

March 26, 2021
2006-me was an idiot

Hopefully in 2036 I'm not calling 2021-me an idiot, too. Here's an interesting old bug situation:

Dan Worrall posted a video on the 1175 JSFX, which was written by Scott Stillwell, way back in 2006, and graciously provided for inclusion with REAPER. In this video, Dan finds that the ratio control is completely broken, and posits a fix to it (adding a division by 2.1).

Sure enough, the code was broken. I went looking through the code1 to see why, and sure enough, there's a line which includes a multiply by 2.08136898, which seems completely arbitrary and incorrect! OK, so we see the bug 2. How did that constant get there?

When the 1175 JSFX was originally written, REAPER and JSFX were very young, and the JSFX log() (natural log, we'll call it by ln() from now on) and log10() implementations were broken. On a 8087 FPU, there are instructions to calculate logarithms, but they work in base 2, so to calculate ln(x) you use log2(x)/log2(e) 3. Prior to REAPER 1.29 it was mistakenly log2(x)*log2(e), due to the ordering of an fdiv being wrong4 and insufficient (or non-existent, rather) testing. So when that got fixed, it actually fixed various JSFX to behave correctly, and that should've been the end of it. This is where the stupid part comes in.

I opted to preserve the existing behavior of existing JSFX for this change, modifying code that used log() functions to multiply log2(e)*log2(e), which is .... 2.08136898. Doh. I should've tested these plug-ins before deciding to make the change. Or at least understood them.

Anyway, that's my story for the day. I'm rolling my eyes at my past self. As a footnote, schwa found that googling that constant finds some interesting places where that code has been reused, bug and all.

* 1 (beyond our SVN commits and all the way back to our VSS commits, all of which have thankfully been imported into git)
* 2 (and it will be fixed in REAPER 6.26, we're calling the non-fixed mode "Broken Capacitor" because that felt about right)
* 3 (or if you're clever and care about speed, log2(x)*ln(2) because ln(X) = logX(X)/logX(e) and logX(X)=1, but now my head hurts from talking about logarithms)
* 4 I haven't fully tested but I think it was working correctly on Jesusonic/linux, and when porting the EEL2 code to MSVC I didn't correctly convert it.

Posted by Zoom on Sat 27 Mar 2021 at 05:49 from 88.201.132.x

Reads like you have a complete Linux userspace written in JS to replace GNU. That would be hilarious, but I wouldn't be surprised.

Posted by Justin on Sat 27 Mar 2021 at 09:41 from 71.167.52.x
hah! still using gnu libc etc, but iirc busybox and replaced /bin/init with a shell script :)

Add comment:
Human?: (no or yes, patented anti crap stuff here)
search : rss : recent comments : Copyright © 2021 Justin Frankel