| Jim,
I played around with your example and concluded that the problem may
be some rounding error with integer formatting (%d).
Here's my example, followed by the output:
sr = 44100
ksmps = 1
nchnls = 1
instr 1
kval init -5.0001
knorepeat init 0
if (knorepeat == 0) then
printks "kval is %d with d. ", 0, kval
printks "kval is %5.2f with f. ", 0, kval
endif
knorepeat = 1
endin
i1 0 0.1
Csound version 5.14 (float samples) Oct 10 2011
0dBFS level = 32768.0
orch now loaded
audio buffered in 256 sample-frame blocks
PortAudio V19-devel (built Feb 12 2010 09:42:54)
PortAudio: available output devices:
0: Built-in Output
1: Built-in Line Output
2: Built-in Digital Output
3: Audio Kontrol 1
PortAudio: selected output device 'Audio Kontrol 1'
writing 512-byte blks of shorts to dac3
SECTION 1:
new alloc for instr 1:
kval is -4 with d. kval is -5.00 with f. Score finished in
csoundPerformKsmps().
inactive allocs returned to freespace
end of score. overall amps: 0.0
overall samples out of range: 0
0 errors in performance
18 512-byte soundblks of shorts written to dac3
On Jul 1, 2012, at 2:12 AM, Jim Aikin wrote:
> While trying to track down a bug in my own code (found it
> eventually), I had
> recourse to printks. For a while, I was flummoxed by the fact that an
> important variable was taking on an obviously impossible value. This
> variable could ONLY be set in my code to 0 or -2, but printks was
> reporting
> it as -1.
>
> After tearing my hair out for about twenty minutes because I thought
> that
> must be the source of my bug, I discovered that printks was simply
> giving me
> erroneous information. The actual value of my variable was indeed -2.
>
> Here's a test .csd that shows the problem:
>
>
>
>
>
> sr = 44100
> ksmps = 1
> nchnls = 1
>
> instr 1
> kval init -2
> knorepeat init 0
> if (knorepeat == 0) then
> printks "kval is %d with d.\n", 0, kval
> printks "kval is %f with f.\n", 0, kval
> endif
> knorepeat = 1
> endin
>
>
>
> i1 0 0.1
>
>
>
> And here's the output:
>
> new alloc for instr 1:
> kval is -1 with d.
> kval is -2.000000 with f.
>
> I would guess this may have something to do with floating-point math,
> minuscule rounding errors, and the fact that I happened to be using a
> negative number. I frankly don't think that matters. printks ought
> to give a
> humanly sensible output, even with a negative number. (With a positive
> number, both print statements report 2.)
>
> --Jim Aikin
>
>
>
>
>
> --
> View this message in context: http://csound.1045644.n5.nabble.com/Bug-in-printks-tp5713994.html
> Sent from the Csound - General mailing list archive at Nabble.com.
>
>
> Send bugs reports to the Sourceforge bug tracker
> https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body
> "unsubscribe csound"
>
|