Csound Csound-dev Csound-tekno Search About

sprintf and fractional values [was Re: [Csnd] more python]

Date2013-04-18 20:04
Frompeiman khosravi
Subjectsprintf 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>


Date2013-04-18 20:14
FromLouis Cohen
SubjectRe: 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  wrote:

> 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
> 
> 
> 
> 
> 
> 
> 
> -odac -d -A -3 -b1024 -B1024
> 
> 
> 
> sr     = 44100
> kr     = 4410
> ksmps  = 10
> nchnls = 2
> 
> instr 3
> ifrac = frac(p1)
> print ifrac
> Sfreq sprintf  "freq.%g", ifrac
> prints Sfreq
> endin
> 
> 
> 
> 
> 
> i3.1 0 1
> 
> 
> 
> 
> 

Lou Cohen
www.jolc.net
www.opensound.org






Date2013-04-18 20:16
Frompeiman khosravi
SubjectRe: 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.

-Lou

On Apr 18, 2013, at 3:04 PM, peiman khosravi <peimankhosravi@gmail.com> wrote:

> 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>
>

Lou Cohen
www.jolc.net
www.opensound.org






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"



Date2013-04-18 22:09
FromJustin Smith
SubjectRe: 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:
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.

-Lou

On Apr 18, 2013, at 3:04 PM, peiman khosravi <peimankhosravi@gmail.com> wrote:

> 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>
>

Lou Cohen
www.jolc.net
www.opensound.org






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"




Date2013-04-18 22:10
Frompeiman khosravi
SubjectRe: 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:
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:
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.

-Lou

On Apr 18, 2013, at 3:04 PM, peiman khosravi <peimankhosravi@gmail.com> wrote:

> 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>
>

Lou Cohen
www.jolc.net
www.opensound.org






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"





Date2013-04-18 22:13
FromJustin Smith
SubjectRe: 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:
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:
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:
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.

-Lou

On Apr 18, 2013, at 3:04 PM, peiman khosravi <peimankhosravi@gmail.com> wrote:

> 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>
>

Lou Cohen
www.jolc.net
www.opensound.org






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"