sprintf and fractional values [was Re: [Csnd] more python]
Date | 2013-04-18 20:04 |
From | peiman khosravi |
Subject | sprintf and fractional values [was Re: [Csnd] more python] |
I'm trying to use the following code (below the email) but the result is this: instr 3: ifrac = 0.100 freq.0.0999999B 0.000 .. 1.000 T 1.000 TT 1.000 M: 0.0 0.0
Now if I change the instrument number to 1 I get this: instr 1: ifrac = 0.100 freq.0.1B 0.000 .. 1.000 T 1.000 TT 1.000 M: 0.0 0.0
Have I missed something in the documentation?
Thanks P <CsoundSynthesizer> <CsOptions> -odac -d -A -3 -b1024 -B1024
</CsOptions> <CsInstruments> sr = 44100 kr = 4410
ksmps = 10 nchnls = 2 instr 3 ifrac = frac(p1) print ifrac
Sfreq sprintf "freq.%g", ifrac prints Sfreq endin
</CsInstruments> <CsScore> i3.1 0 1 </CsScore>
</CsoundSynthesizer> |
Date | 2013-04-18 20:14 |
From | Louis Cohen |
Subject | Re: sprintf and fractional values [was Re: [Csnd] more python] |
I'm no expert, but I would guess that 0.0999999B and 0.1B are essentially the same number. -Lou On Apr 18, 2013, at 3:04 PM, peiman khosravi |
Date | 2013-04-18 20:16 |
From | peiman khosravi |
Subject | Re: sprintf and fractional values [was Re: [Csnd] more python] |
Not if you're converting them to string after! I'll try rounding it and see what happens. www.peimankhosravi.co.uk
To receive emails about upcoming concerts visit this page & enter your email address in the 'follow' section. On 18 April 2013 20:14, Louis Cohen <loucohen@jolc.net> wrote: I'm no expert, but I would guess that 0.0999999B and 0.1B are essentially the same number. |
Date | 2013-04-18 22:09 |
From | Justin Smith |
Subject | Re: sprintf and fractional values [was Re: [Csnd] more python] |
frac(3.1) and frac(1.1) are different numbers in ieee floating point if you are using 32 bit precision On Thu, Apr 18, 2013 at 12:16 PM, peiman khosravi <peimankhosravi@gmail.com> wrote:
|
Date | 2013-04-18 22:10 |
From | peiman khosravi |
Subject | Re: sprintf and fractional values [was Re: [Csnd] more python] |
I see. That makes sense. Thanks for the explanation. I'm using the double version on the desktop computer and that's why it's working there.
Cheers, P www.peimankhosravi.co.uk To receive emails about upcoming concerts visit this page & enter your email address in the 'follow' section. On 18 April 2013 22:09, Justin Smith <noisesmith@gmail.com> wrote:
|
Date | 2013-04-18 22:13 |
From | Justin Smith |
Subject | Re: sprintf and fractional values [was Re: [Csnd] more python] |
just a quick calculation (in my clojure repl, the float function creates a 32 bit number): user> (frac (float 3.1)) 0.09999990463256836 user> (frac (float 1.1)) 0.10000002384185791 On Thu, Apr 18, 2013 at 2:10 PM, peiman khosravi <peimankhosravi@gmail.com> wrote:
|