Csound Csound-dev Csound-tekno Search About

[Csnd] rounding

Date2009-12-11 16:37
FromMatt Barber
Subject[Csnd] rounding
Hello,

I am trying to find out what kind of rounding the round() opcode does.
 I've been going through the csound code, and I want to make sure I'm
understanding it correctly:

It seems as though the type of rounding is system-dependent, but that
if lrint() or lrintf() is defined in the c library it is used?  Does
anyone know if lrint rounds 0.5 to the nearest even number (so called
"banker's round") by default?  I notice some of the provided functions
to be used in place of lrint round 0.5 away from zero.  I am assuming
that on most linux distros that lrint()/lrintf() will be used and that
it will round 0.5 to nearest even, but I wanted to check this with the
list...  I suppose I could just create a diagnostic orc/score to find
out what it's doing on my system, but I might need to open my project
in another linux distro soon and I don't want to go in with poor
assumptions.


Thanks,

Matt


Send bugs reports to this list.
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2009-12-11 16:48
FromJacob Joaquin
Subject[Csnd] Re: rounding
While we're on the subject I came across this line in the manual, and
found it somewhat unsatisfactory, "The integer value nearest to x ; if
the fractional part of x is exactly 0.5, the direction of rounding is
undefined."

Shouldn't a function like this have a clearly defined behavior?

On OS X, round(0.5) produces 0, while round(1.5) produces 2.  I pretty
much stay away from round, and prefer going with either int(ifoo +
0.5) or floor(ifoo + 0.5).

Best,
Jake
-- 
The Csound Blog - http://csound.noisepages.com/


On Fri, Dec 11, 2009 at 8:37 AM, Matt Barber  wrote:
> Hello,
>
> I am trying to find out what kind of rounding the round() opcode does.
>  I've been going through the csound code, and I want to make sure I'm
> understanding it correctly:
>
> It seems as though the type of rounding is system-dependent, but that
> if lrint() or lrintf() is defined in the c library it is used?  Does
> anyone know if lrint rounds 0.5 to the nearest even number (so called
> "banker's round") by default?  I notice some of the provided functions
> to be used in place of lrint round 0.5 away from zero.  I am assuming
> that on most linux distros that lrint()/lrintf() will be used and that
> it will round 0.5 to nearest even, but I wanted to check this with the
> list...  I suppose I could just create a diagnostic orc/score to find
> out what it's doing on my system, but I might need to open my project
> in another linux distro soon and I don't want to go in with poor
> assumptions.
>
>
> Thanks,
>
> Matt
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>


Send bugs reports to this list.
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2009-12-11 17:35
Frombrbrofsvl
Subject[Csnd] Re: rounding
I think by "undefined" they just mean that it's defined differently in the C
preprocessor depending on what's available to the system -- which means that
the manual can't afford to describe a definitive behavior.  The behavior you
describe in OSX sounds like the "banker's round," which is superior to the
floor rounder if you are doing processing that for one reason or another has
a lot of x.5 values, since it cancels the upward bias. 



Jacob Joaquin wrote:
> 
> While we're on the subject I came across this line in the manual, and
> found it somewhat unsatisfactory, "The integer value nearest to x ; if
> the fractional part of x is exactly 0.5, the direction of rounding is
> undefined."
> 
> Shouldn't a function like this have a clearly defined behavior?
> 
> On OS X, round(0.5) produces 0, while round(1.5) produces 2.  I pretty
> much stay away from round, and prefer going with either int(ifoo +
> 0.5) or floor(ifoo + 0.5).
> 
> Best,
> Jake
> -- 
> The Csound Blog - http://csound.noisepages.com/
> 
> 
> On Fri, Dec 11, 2009 at 8:37 AM, Matt Barber  wrote:
>> Hello,
>>
>> I am trying to find out what kind of rounding the round() opcode does.
>>  I've been going through the csound code, and I want to make sure I'm
>> understanding it correctly:
>>
>> It seems as though the type of rounding is system-dependent, but that
>> if lrint() or lrintf() is defined in the c library it is used?  Does
>> anyone know if lrint rounds 0.5 to the nearest even number (so called
>> "banker's round") by default?  I notice some of the provided functions
>> to be used in place of lrint round 0.5 away from zero.  I am assuming
>> that on most linux distros that lrint()/lrintf() will be used and that
>> it will round 0.5 to nearest even, but I wanted to check this with the
>> list...  I suppose I could just create a diagnostic orc/score to find
>> out what it's doing on my system, but I might need to open my project
>> in another linux distro soon and I don't want to go in with poor
>> assumptions.
>>
>>
>> Thanks,
>>
>> Matt
>>
>>
>> Send bugs reports to this list.
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
>> csound"
>>
> 
> 
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
> csound"
> 

-- 
View this message in context: http://old.nabble.com/rounding-tp26747459p26748426.html
Sent from the Csound - General mailing list archive at Nabble.com.



Send bugs reports to this list.
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2009-12-11 17:59
FromJacob Joaquin
Subject[Csnd] Re: Re: rounding
Based on the output of the code below, it certainly seems that the
banker's round is what is being used on OS X.



i_index = -10
loop_start:
    prints "%d:  %f\n", i_index, round(i_index + 0.5)
loop_lt i_index, 1, 10, loop_start
instr 1
endin






If anyone would like to run that and report their output, I'm curious
to see if there are differences between different systems.  As for the
manual, would it make sense to give a reason as to why values of 0.5
might be undefined?  Knowing why some things differ on different
systems could help avoid some confusion down the road.

Best,
Jake
-- 
The Csound Blog - http://csound.noisepages.com/


On Fri, Dec 11, 2009 at 9:35 AM, brbrofsvl  wrote:
>
> I think by "undefined" they just mean that it's defined differently in the C
> preprocessor depending on what's available to the system -- which means that
> the manual can't afford to describe a definitive behavior.  The behavior you
> describe in OSX sounds like the "banker's round," which is superior to the
> floor rounder if you are doing processing that for one reason or another has
> a lot of x.5 values, since it cancels the upward bias.


Send bugs reports to this list.
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2009-12-11 20:43
Frombrbrofsvl
Subject[Csnd] Re: Re: rounding
I can confirm round to nearest even on Fedora with this test.

MB



Jacob Joaquin wrote:
> 
> Based on the output of the code below, it certainly seems that the
> banker's round is what is being used on OS X.
> 
> 
> 
> i_index = -10
> loop_start:
>     prints "%d:  %f\n", i_index, round(i_index + 0.5)
> loop_lt i_index, 1, 10, loop_start
> instr 1
> endin
> 
> 
> 
> 
> 
> 
> If anyone would like to run that and report their output, I'm curious
> to see if there are differences between different systems.  As for the
> manual, would it make sense to give a reason as to why values of 0.5
> might be undefined?  Knowing why some things differ on different
> systems could help avoid some confusion down the road.
> 
> Best,
> Jake
> -- 
> The Csound Blog - http://csound.noisepages.com/
> 
> 
> On Fri, Dec 11, 2009 at 9:35 AM, brbrofsvl  wrote:
>>
>> I think by "undefined" they just mean that it's defined differently in
>> the C
>> preprocessor depending on what's available to the system -- which means
>> that
>> the manual can't afford to describe a definitive behavior.  The behavior
>> you
>> describe in OSX sounds like the "banker's round," which is superior to
>> the
>> floor rounder if you are doing processing that for one reason or another
>> has
>> a lot of x.5 values, since it cancels the upward bias.
> 
> 
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
> csound"
> 

-- 
View this message in context: http://old.nabble.com/rounding-tp26747459p26751180.html
Sent from the Csound - General mailing list archive at Nabble.com.



Send bugs reports to this list.
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"