Old 10-26-2019, 09:33 AM   #1
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 7,416
Default How is divide by zero handled...?

The following snippet is from the 50 Hz Kicker JSFX that comes with Reaper.

Code:
gain = min(max(env2/env1,1)-1,1) * wet;
The thing here is that if Reaper is stopped and nothing is playing through the JSFX, both env1 and env2 become zero. And the strange thing is that if Reaper is not playing for close to 4 minutes, the 50 Hz Kicker starts emitting a sine wave of the set frequency at the gain set by the "wet" variable.

I can only assume that this is because the divide by zero inside the max somehow makes the whole max-min expression suddenly return 1, so that gain is set to the value of wet.

But if this assumption is correct, that behavior seems very strange. I understand that divide by zero is undefined, but still... I would expect some consistent behavior.
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
Fabian is offline   Reply With Quote
Old 10-30-2019, 02:27 PM   #2
ashcat_lt
Human being with feelings
 
Join Date: Dec 2012
Posts: 7,271
Default

I think you're asking for something deeper, and I'm not sure that this is exactly why it does what you're hearing, but in this case it basically is not handled. JS does...something...but the only way to be sure what that is would be explicitly handle the case in the code. I'd be inclined to just tell it that IF env1 = 0 THEN gain = 0.
ashcat_lt is online now   Reply With Quote
Old 10-30-2019, 04:34 PM   #3
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,618
Default

When you divide by zero in JSFX, a micro black hole is spawned which establishes a quantumly entangled relationship to a JSFX instance in a parallel universe. At this moment, the result of the calculation is simultaneously both 0 and 1, however once the next opcode begins evaluation, the waveform collapses and one of the values manifests during execution. Unfortunately the Heisenberg uncertainty principle means it is not possible to predict which of the results will be produced by the JSFX (in our universe).
tack is offline   Reply With Quote
Old 10-31-2019, 12:40 AM   #4
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,686
Default

It's amazing in what elaborated ways the devs avoid Reaper from crashing in such situations !
-Michael
mschnell is offline   Reply With Quote
Old 10-31-2019, 10:23 AM   #5
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 7,416
Default

Thanks guys, for your all deep insight into this

Quote:
Originally Posted by ashcat_lt View Post
<snip>
I'd be inclined to just tell it that IF env1 = 0 THEN gain = 0.
Yes, I did that and it works.
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
Fabian is offline   Reply With Quote
Old 10-31-2019, 11:29 AM   #6
karbomusic
Human being with feelings
 
karbomusic's Avatar
 
Join Date: May 2009
Posts: 29,260
Default

^Correct, the way to avoid /0 is to check the value before doing the division.
__________________
Music is what feelings sound like.
karbomusic is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 08:55 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.