Author |
Message |
kijjaz

Joined: Sep 20, 2004 Posts: 765 Location: bangkok, thailand
Audio files: 4
|
Posted: Sat Nov 04, 2006 10:46 am Post subject:
Floating-point Exception Error? Subject description: What caused it? |
 |
|
today i'm working on a code..
and it caused floatingpoint exception error
(make chuck quit, and miniAudicle die)
what caused that?
this is the code:
Code: | TriOsc s1 => NRev r => dac;
TriOsc s2 => r;
0.4 => r.gain;
0 => int x => int y;
while (true) {
(x + 7) % y => int newx;
(y + 11) % x => int newy;
Std.mtof(x + 40) => s1.freq;
Std.mtof(y + 40) => s2.freq;
400 :: ms => now;
newx => x; newy => y;
}
|
|
|
Back to top
|
|
 |
Blue Hell
Site Admin

Joined: Apr 03, 2004 Posts: 23504 Location: The Netherlands, Enschede
Audio files: 262
G2 patch files: 320
|
Posted: Sat Nov 04, 2006 11:40 am Post subject:
|
 |
|
Probably the % x and % y operations. the % operation performs a division to calculate a remainder and initially x and y are zero. A division by zero is not allowed (undefined) and results in an exception.
It is not really nice that the software dies on that tho. _________________ Jan
also .. could someone please turn down the thermostat a bit.
 |
|
Back to top
|
|
 |
jbum

Joined: Oct 24, 2006 Posts: 26 Location: Los Angeles
|
Posted: Sat Nov 04, 2006 11:46 am Post subject:
|
 |
|
(This was crossposted with the previous msg...)
The crashing is triggered by a division by zero in these two lines:
Code: |
(x + 7) % y => int newx;
(y + 11) % x => int newy;
|
I should point out a couple of things:
1) Since x and y start at zero, newx and newy will always evaluate to zero using this code. It is quite likely that (% x) is triggering a divide by zero, due to ChucK's implementation of modulo. I tried initializinng x and y to a larger value, and it seemed to get a little further before crashing, but it still crashed, because eventually, x and y take on a value of zero.
2) The precedence of the ChucK operator (=>) seems too high to me. Invariablly, I have to put parenthesis around everything I am passing to it... e.g.
(x * y) => value
as opposed to
x * 7 => value
Here's a version that works okay, by avoiding zero...
Code: |
TriOsc s1 => NRev r => dac;
TriOsc s2 => r;
0.4 => r.gain;
0 => int x => int y;
while (true) {
if (x == 0)
100 => x;
if (y == 0)
100 => y;
((x + 7) % y) => int newx;
((y + 11) % x) => int newy;
Std.mtof(40) => s1.freq;
Std.mtof(40) => s2.freq;
400 :: ms => now;
newx => x; newy => y;
}
|
_________________ <a href="http://www.krazydad.com/">krazydad.com</a> |
|
Back to top
|
|
 |
kijjaz

Joined: Sep 20, 2004 Posts: 765 Location: bangkok, thailand
Audio files: 4
|
Posted: Sun Nov 05, 2006 3:06 pm Post subject:
|
 |
|
ohhhhhhhhh hahhhhahahha yessss...
i forgot about that...
hooooo... hahahhaahah oh how could i forget.. ?
but i understand.. it was 4am at that time and i'm a little drunk.
- - -
it turned out to be this..
thanks for helping.
this is one of my experiment on the melody part.
Code: | Mandolin s1 => PRCRev r;
Mandolin s2 => r;
r => dac;
s1 => pan2 p1 => dac;
s2 => pan2 p2 => dac;
-1 => p1.pan;
1 => p2.pan;
[4.0, 1, 0.5, 0.5, 2, 1, 1] @=> float rhythm1[];
0.4 :: second => dur beat;
0.1 => r.gain;
0.5 => s1.gain;
0.5 => s2.gain;
1=> r.mix;
0 => int x => int y;
int newx, newy;
int t;
while (true) {
if (x == 0)
25 => x;
if (y == 0)
13 => y;
((x + maybe * 3 + 2) % y) => newx;
((y + 7) % x) => newy;
Std.mtof(x + 64) => s1.freq;
Std.mtof(y + 40) => s2.freq;
newx => x; newy => y;
s1.pluck(1); s2.pluck(0.7);
rhythm1[t % rhythm1.cap()] * .5 :: beat => now;
t++;
} |
|
|
Back to top
|
|
 |
|