Csound Csound-dev Csound-tekno Search About

[Cs-dev] Score expressions

Date2008-01-29 22:02
FromAnthony Kozar
Subject[Cs-dev] Score expressions
I am revising the manual section "Evaluation of Expressions" to include some
information that was previously omitted.  I want to check that the following
is correct (particularly the parts about right to left evaluation and
precedence of logical operators).

-----------
    In earlier versions of Csound the numbers presented in a score were used
as given.  There are occasions when some simple evaluation would be easier.
This need is increased when there are macros.  To assist in this area the
syntax of arithmetic expressions within square brackets [ ] has been
introduced.  Expressions built from the operations +, -, *,  /, %
("modulo"), and ^ ("power of") are allowed, together with grouping with ( ).
Unary minus and plus are also supported. The expressions can include
numbers, and naturally macros whose values are numeric or arithmetic
strings.  All calculations are made in floating point numbers. The usual
precedence rules are followed when evaluating: expressions within
parantheses ( ) are evaluated first and ^ is evaluated before *, /, and %
which are evaluated before + and -.  Note that operations of the same
precedence are evaluated from right to left, not the usual left to right.

    In addition to arithmetic operations, the following bitwise logical
operators are also available: & (AND), | (OR), and # (XOR, exclusive-OR).
These operators round their operands to the nearest (long) integer before
evaluating.  The logical operators have the same precedence as the *, /, and
% arithmetic operators.

    Finally, the tilde symbol ~ can be used anywhere in an expression that a
number is permissible to provide a random value between zero (0) and one
(1).
------------

Anthony


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2008-01-29 22:04
FromVictor.Lazzarini@nuim.ie
SubjectRe: [Cs-dev] Score expressions
AttachmentsNone  None  None  None  

Date2008-01-30 01:26
FromAnthony Kozar
SubjectRe: [Cs-dev] Score expressions
Victor, my meaning is more like your second statement -- "wherever a number
is permissible" -- because there are other things that can occur in these
places too (the @ operator, parantheses).  Thanks, I will try to clarify the
sentence and perhaps provide an example.

Regarding precedence and order of evalution:  I have done a few more tests,
and of course for expressions like [ 8 / 2 / 2 ] and [ 4 + 3 - 2 + 1 ], the
order of evaluation is left to right (giving 2 and 6).  However, for
expressions like the following, I seem to be getting right-to-left
evaluation:

  [ 2 * 2 & 3 ]             ; gives 4, not 0
  [ 3 & 2 * 2 ]             ; gives 0, not 4
  [ 4 | 3 * 3 ]             ; gives 13, not 21
  [ 3 * 1 & 3 * 3 & 3 * 7 ] ; gives 3, not 7

So, it appears that & and | have the same precedence as * but then the whole
expression is evaluated in reverse?  Can anyone make some sense of this so
that I can describe it correctly?

Thanks.

Anthony

Victor.Lazzarini@nuim.ie wrote on 1/29/08 5:04 PM:

> The paragraph on tilde ~ is not very clear, I am not
> sure what the text implies. Would it be something
> like 
> "The tilde symbol can be used anywhere in an expression
> in place of a number..."
> or
> "...can be used in an expression
> wherever a number is permissible, to provide..."
> 
> Victor
> 
> ----- Original Message -----
> From: Anthony Kozar 
> Date: Tuesday, January 29, 2008 9:59 pm
> Subject: [Cs-dev] Score expressions
> To: New Csound Developer list 

>> Note that operations of the same
>> precedence are evaluated from right to left, not the usual left
>> to right.
 
>> The logical operators have the same precedence
>> as the *, /, and
>> % arithmetic operators.

>> Finally, the tilde symbol ~ can be used
>> anywhere in an expression that a
>> number is permissible to provide a random value between zero (0)
>> and one (1).


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net