[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Unary Operators and their Level of Precedence



PureBytes Links

Trading Reference Links


Udo,
 
I know this table well :-)
 
But this table is for C++ language not for AFL.
AFL has much less operators.
1. There is no unary plus in AFL so we can not talk if unary 
minus has a greater or lower precedence than plus in AFL :-)
2. There are no increment/decrement operators ++, -- 
in AFL 
 
As I understand we were talking all the time about the AFL not 
C.
 
Also I can not agree that unary plus and minus are assignment 
operators. They have nothing to do with an assignment.
Best 
regards,Tomasz Janeczkoamibroker.com
<BLOCKQUOTE 
>
----- Original Message ----- 
<DIV 
>From: 
<A title=Udo.Harke@xxxx 
href="">Udo.Harke@xxxx 
To: <A title=amibroker@xxxxxxxxxx 
href="">amibroker@xxxxxxxxxxxxxxx 
Sent: Tuesday, April 30, 2002 8:42 
PM
Subject: [amibroker] Unary Operators and 
their Level of Precedence

Hi Tomasz,
 
Technically, increment and decrement 
unary operators are assignment operators as well as 
the unary minus (-) and unary plus (+) 
operators:
 
In C++, the unary minusand 
unary plus operators have a different level of precedence. The 
same holds for the prefix and postfix form of the 
increment/decrement operators.
Unfortunately, that understanding is 
confused and misrepresented in many C/C++ books!
For your reference, you 
may refer to Operator Precedence and Associativity in 
MSDN Library Visual Studio 6.0 or, otherwise, please take a 
look at the table below, which I obtained from that library.
<FONT face="Courier New" 
size=2> 
Regards,
 
Udo<FONT 
face=Verdana size=2> 

<A 
name=_langref_operator_precedence_and_associativity><FONT 
face=Arial color=#0000ff size=2>Operator Precedence and 
Associativity
The table below lists the C and C++ 
operators and their precedence and associativity values. The highest 
precedence level is at the top of the table.



<FONT face=Arial color=#0000ff 
size=2>Symbol
<FONT face=Arial color=#0000ff 
size=2>Name or Meaning
<FONT face=Arial color=#0000ff 
size=2>Associativity

 
Highest 
Precedence
<FONT face=Arial color=#0000ff 
size=2> 

++
<FONT face=Arial color=#0000ff 
size=2>Post-increment
Left to 
right

<FONT face=Arial color=#0000ff 
size=2>--
<FONT face=Arial color=#0000ff 
size=2>Post-decrement
<FONT face=Arial color=#0000ff 
size=2> 

( )
Function 
call
<FONT face=Arial color=#0000ff 
size=2> 

[ ]
Array 
element
<FONT face=Arial color=#0000ff 
size=2> 

<FONT 
color=#0000ff>->
Pointerto 
structure member
<FONT face=Arial color=#0000ff 
size=2> 

.
Structure or union 
member
<FONT face=Arial color=#0000ff 
size=2> 

++
<FONT face=Arial color=#0000ff 
size=2>Pre-increment
Right to 
left

<FONT face=Arial color=#0000ff 
size=2>--
<FONT face=Arial color=#0000ff 
size=2>Pre-decrement
<FONT face=Arial color=#0000ff 
size=2> 

!
Logical 
NOT
<FONT face=Arial color=#0000ff 
size=2> 

~
Bitwise 
NOT
<FONT face=Arial color=#0000ff 
size=2> 

<FONT face=Arial color=#0000ff 
size=2>-
Unary 
minus
<FONT face=Arial color=#0000ff 
size=2> 

+
Unary 
plus
<FONT face=Arial color=#0000ff 
size=2> 

&
Address
<FONT face=Arial color=#0000ff 
size=2> 

*
<FONT face=Arial color=#0000ff 
size=2>Indirection
<FONT face=Arial color=#0000ff 
size=2> 

sizeof
Size in 
bytes
<FONT face=Arial color=#0000ff 
size=2> 

new
Allocate program 
memory
<FONT face=Arial color=#0000ff 
size=2> 

delete
Deallocate program 
memory
<FONT face=Arial color=#0000ff 
size=2> 

(type)
Type cast [for 
example, (float) i]
<FONT face=Arial color=#0000ff 
size=2> 

<FONT 
color=#0000ff>.*
Pointerto member 
(objects)
Left to 
right

<FONT 
color=#0000ff>->*
Pointerto member 
(pointers)
<FONT face=Arial color=#0000ff 
size=2> 

*
Multiply
Left to 
right

/
Divide
<FONT face=Arial color=#0000ff 
size=2> 

%
<FONT face=Arial color=#0000ff 
size=2>Remainder
<FONT face=Arial color=#0000ff 
size=2> 

+
Add
Left to 
right

<FONT face=Arial color=#0000ff 
size=2>-
Subtract
<FONT face=Arial color=#0000ff 
size=2> 

<<
Left 
shift
Left to 
right

>>
Right 
shift
<FONT face=Arial color=#0000ff 
size=2> 

<
Less 
than
Left to 
right

<=
Less than or equal 
to
<FONT face=Arial color=#0000ff 
size=2> 

>
Greater 
than
<FONT face=Arial color=#0000ff 
size=2> 

>=
Greaterthan or 
equal to
<FONT face=Arial color=#0000ff 
size=2> 

==
Equal
Left to 
right

!=
Not 
equal
<FONT face=Arial color=#0000ff 
size=2> 

&
Bitwise 
AND
Left to 
right

^
Bitwiseexclusive 
OR
Left to 
right

|
Bitwise 
OR
Left to 
right

<FONT face=Arial color=#0000ff 
size=2>&&
Logical 
AND
Left to 
right

||
Logical 
OR
Left to 
right

? 
:
<FONT face=Arial color=#0000ff 
size=2>Conditional
Right to 
left

=
<FONT face=Arial color=#0000ff 
size=2>Assignment
Right to 
left

*=, /=, %=, +=, 
-=, <<=, >>=, &=, ^=, |=
Compound 
assignment
<FONT face=Arial color=#0000ff 
size=2> 

,
Comma
Left to 
right

 
Lowest 
Precedence
<FONT face=Arial color=#0000ff 
size=2> 
 
 
<BLOCKQUOTE 
>
-----Ursprüngliche Nachricht----- 
<DIV 
>Von: 
Tomasz Janeczko 

An: <A title=amibroker@xxxxxxxxxxxx 
href="">amibroker@xxxxxxxxxxxxxxx
Gesendet: Dienstag, den 30. April 2002 
16:53 Uhr
Betreff: Re: [amibroker] Re: Areyour 
Composites accurate???
Richard,I just checked the parser code.You are 
right unary minus has precedence over exponentiation.I think I should 
change this behaviour to match documentation.Best regards,Tomasz 
Janeczkoamibroker.com----- Original Message -----From: "Richard 
Alford" <<A 
href="">richard.alford@xxxx>To: 
<<A 
href="">amibroker@xxxxxxxxxxxxxxx>Sent: 
Tuesday, April 30, 2002 3:27 PMSubject: Re: [amibroker] Re: Are your 
Composites accurate???> Tomasz,>> I don't see 
anything unusual or surprising in what you say.  The only> 
issue/question I have, and it is purely academic, is whether your> 
documentation is, in fact, in minor error by showing exponentiation 
as> higher precedence than the unary minus. Just for curiosity, can 
you give an> example where exponentiation has higher precedence?I 
have yet to see> anything in this thread that gives a surprising 
result to me.>> Cheers,>> Richard> ----- 
Original Message -----> From: "Tomasz Janeczko" <<A 
href="">amibroker@xxxx>> To: <<A 
href="">amibroker@xxxxxxxxxxxxxxx>> 
Sent: Tuesday, April 30, 2002 3:36 AM> Subject: Re: [amibroker] Re: 
Are your Composites accurate???>>> > 
Richard,> >> > The - (unary minus) operator negatesthe 
value of the operand.> >> > The result of applying the 
unary minus operator to a signed operand is> > equivalent to the 
negative promoted type of the operand.> >> > For 
example, if quality has the value 100, then -quality has the> value 
-100.> >> > The unary minus has right associativityand 
higher precedence  than most> other> > operators 
(except exponentiation)> > In the first Dimitris example the minus 
sign is treated as> > binary minus (regular subtraction) there 
fore the result is 10 - (3^2) => 10 - 9 = 1> > In the 
second Dimitirs example the minus sign follows addition> > 
operator. Addition (binary plus operator) expects numbers from left 
and> right side.> > This time minus is treated as unary 
minus operator> > So this is evaluated as:> >> 
> 10 + ( (-3)^2 ) = 10 + 9 = 19> >> > (right 
associativity of unary minus and precedence over binary plus> 
operator).> >> > Best regards,> > Tomasz 
Janeczko> > amibroker.com> > ----- Original Message 
-----> > From: "dtsokakis" <<A 
href="">TSOKAKIS@xxxx>> > To: 
<<A 
href="">amibroker@xxxxxxxxxxxxxxx>> 
> Sent: Tuesday, April 30, 2002 9:07 AM> > Subject: [amibroker] 
Re: Are your Composites accurate???> >> >> > 
Richard,> > Note please that in AFL the following results are 
true:> > 10-3^2=1> > 10+-3^2=19> > !!!> 
> Dimitris Tsokakis> > --- In <A 
href="">amibroker@xxxx..., "Richard Alford" <<A 
href="">richard.alford@xxxx...> wrote:> 
> > not in this universe :)  It may not, in fact, matter since 
the> > exponentiation operator always (by some other convention?) 
follows> > the operand.  Actually the "unitary" is a 
relatively new term (in the> > past 20 years) jumping out after I 
was well out of grad school (in> > mathematical physics) and 
before the programmers began to worry about> > the difference 
between subtraction and what I always interpreted as a> > simple 
negative number - the computer worries about such things,> > 
people don't. (I do realize the mathematical distinction has been> 
> around for centuries - just ignored like most math in the real 
world> > until it found a use.)> > >> > 
> BTW - Multiplication and division are not generally on the same> 
> level ( My Dear Aunt Sally) for the antiques in the group; 
although,> > when in doubt most simply just hammer in parens by 
reflex - similar> > to the way a horse runs first and asks 
questions latter....> > >> > >> > > I 
still think that this is a simple documentation error on TJ's> > 
part , and,personally, I find that comforting :)> > >> 
> > Cheers,> > >> > > Richard> > 
>   ----- Original Message -----> > >   
From: Steve Dugas> > >   To: <A 
href="">amibroker@xxxx...> > >   
Sent: Monday, April 29, 2002 8:34 PM> > >   Subject: 
Re: [amibroker] Re: Are your Composites accurate???> > 
>> > >> > >   It just occurred to me 
- maybe they are on the same level (like> > multiplication and 
division), so it does the negation first because> > it comes to it 
first?> > >> > >   Steve> > 
>     ----- Original Message -----> > 
>     From: Steve Dugas> > 
>     To: <A 
href="">amibroker@xxxx...> > 
>     Sent: Monday, April 29, 2002 9:08 PM> 
> >     Subject: Re: [amibroker] Re: Are your 
Composites accurate???> > >> > >> > 
>     Hi DT,> > >> > 
>     I must be missing something. I tried your plot, 
and  -1^10 did> > evaluate to 1, like you say. But, if 
exponentiation takes precedence> > over negation (as shown inyour 
table), how come it doesnt evaluate> > to -1, like this? :> 
> >> > >     -1^10  =  
-(1^10)  =  -(1)  =  -1> > >> > 
>     Steve> > 
>       ----- Original Message 
-----> > >       From: 
dtsokakis> > >       To: <A 
href="">amibroker@xxxx...> > 
>       Sent: Monday, April 29, 2002 12:16 
PM> > >       Subject: 
[amibroker] Re: Are your Composites accurate???> > >> 
> >> > >       
Herman,> > >       I really don´t 
know how do you realise things.> > 
>       Well, -1^10 is equal to 1.> 
> >       [It acts like (-1)^10 because 
of priorities in operators**> > 
>       [try Plot(-1^10,"",1,1);]> 
> >       -1*10^10 is a huge negative 
number> > >       Another 
Amibroker expression is -1e10, also negative enough.> > 
>       Your formula was not correct, 
because it was excuding stocks> > with> > 
>       open==1 from counting.[seeprevious 
mails to you]> > >       
DT> > >       **Operator 
precedence and the parentheses> > 
>       AFL supports parentheses in 
formulas.> > >> > 
>       Parentheses can be used to control 
the operation precedence> > (the> > 
>       order in which the operators are 
calculated). AmiBroker> > always does> > 
>       operations within the innermost 
parentheses first. When> > parentheses> > 
>       are not used, the precedence is as 
follows (higher precedence> > listed> > 
>       first):> > >> 
> >       No Symbol Meaning>> 
>       1 ^ Exponentiation> > 
>       2 - Negation - Unary minus> 
> >       3 * Multiplication> 
> >       4 / Division> > 
>       5 + Addition> > 
>       6 - Subtraction> > 
>       7 < Less than> > 
>       8 > Greater than> > 
>       9 <=  Less than or equal 
to> > >       10 >= Greater 
than or equal to> > >       11 == 
Equal to> > >       12 != Not 
equal to> > >       13 NOT 
Logical "Not"> > >       14 AND 
Logical "And"> > >       15 OR 
Logical "Or"> > >       16 = 
Variable assignment operator> > >> > 
>       The expression> > 
>> > >       H + L / 
2;> > >       (without 
parenthesis) would be calculated by AmiBroker> > as "L / 
2"> > >       plus "H", since 
division has a higher precedence. This would> > result> 
> >       in a much different value 
than> > >> > >       
(H + L)/2;> > >> > 
>       --- In <A 
href="">amibroker@xxxx..., "Herman van den Bergen"<<A 
href="">psytek@xxxx...>> > wrote:> > 
>       > > -----Original 
Message-----> > >       >> 
From: dtsokakis [mailto:TSOKAKIS@xxxx]> > 
>       > > Sent: Sunday, April 28, 
2002 11:13 AM> > >       > 
> To: amibroker@xxxx...> > 
>       > > Subject: [amibroker]Re: 
Are your Composites accurate???> > 
>       > >> > 
>       > >> > 
>       > > Herman,> > 
>       > > I just noticed that your 
EMPTY is -1^10, ie equal to 1.> > 
>       > > So, your equivalent 
formula is> > >       > > 
EMPTY = 1;> > >       
>> > >       > Just 
realized that -1^10 is not equal to 1 but is -1 * 10^10> > 
>       >> > 
>       > perhaps my code was OK 
anyway?> > >       >> 
> >       > Take care,> > 
>       > Herman.> > 
>       >> > 
>       >> > 
>       >> > 
>       >> > 
>       > > AddToComposite(IIf(Open 
== 1,0,1),"~DataPresent","v",3);> > 
>       > > Do you have in the group 
of your gif some stocks with> > open==1 ?> > 
>       > > This would give some 
explanation.> > >       >> 
DT> > >       > > PS The 
huge negative symbol in AFL is -1e10> > 
>       > > --- In <A 
href="">amibroker@xxxx..., "dtsokakis" <<A 
href="">TSOKAKIS@xxxx...> wrote:> > 
>       > > > Of course I receive 
an identical result list with your> > 
>       > > > EMPTY = 
-1^10;> > >       > > > 
AddToComposite(IIf(Open ==> > 
EMPTY,0,1),"~DataPresent","v",3);> > 
>       > > > Buy= 0;> > 
>       > > > 
f=Foreign("~datapresent","v");> > 
>       > > > 
Filter=f!=101;> > >       > 
> > AddColumn(f,"");> > 
>       > > > EXACTLY the same 
results.> > >       > > 
> To avoid any misuderstanding :your formula works, I> > just 
think> > >       > > > 
Amibroker does not use the open==EMPTY hypothesis,> > because 
if> > >       the> > 
>       > > > ADLAC is not present 
on 16/4/2002, there is no> > reference for> > 
>       ADLAC> > 
>       > > > this date.> 
> >       > > > My opinionis 
from experience, Tomasz knows how> > AddToComposite()>> 
>       > > > works.> > 
>       > > > DT> > 
>       > > > --- In <A 
href="">amibroker@xxxx..., "Dimitris Tsokakis"> 
> <TSOKAKIS@xxxx...>> > 
>       wrote:> > 
>       > > > > I respectfully 
disagree. If you are not concerned> > about bar-> > 
>       by-> > 
>       > > bar> > 
>       > > > accuracy> 
> >       > > > > than you 
are correct. In that case the "1" method> > works fine.> 
> >       As> > 
>       > > > long as you> 
> >       > > > > know that 
this method will pick up holes of several> > days but>> 
>       that> > 
>       > > > it will>> 
>       > > > > not pick up 
single bar holes.> > >      > 
> > >> > >       > 
> > >> > >       > 
> > > Herman,> > >       
> > > > Of course we speak for daily search, bar-by-bar.> 
> >       > > > > I have in 
my ^NDX 4 experimental holes on> > 
>       > > > > 6/1/2000 [1], 
15/2/2000 [1] and 1/3/2000[2]> > 
>       > > > > plus the 
missing ADLAC after 15/4/2002.> > 
>       > > > > As you seefrom 
the exploration, the population> > 
>       > > > > is different 
from 101 exactly these dates.> > 
>       > > > > I do not 
understand the conditions of your graph.> > 
>       > > > > The> 
> >       > > > > 
AddToComposite(1,"~count","v");> > 
>       > > > > Buy=0;> 
> >       > > > > scans 
bar-by-bar every stock for each date.> > 
>       > > > > If the stock is 
present, it adds an 1 and moves to> > the next> > 
>       stock.> > 
>       > > > > If ADLAC is not 
present on 16/4/2002, then the sum> > will be 100> > 
>       > > > > for the certain 
date.> > >       > > > 
> It is impossible to have a 20% error, there should be> > 
another> > >       > >> 
> reason for your results.> > 
>       > > > > Dimitris 
Tsokakis> > >       > 
>> > >       > >> 
> >       > >> > 
>       > >> > 
>       > >> > 
>       > > Your use of Yahoo! Groups 
is subject to> > >       <A 
href="">http://docs.yahoo.com/info/terms/> 
> >       > >> > 
>       > >> > >> 
> >> > >       Your use of 
Yahoo! Groups is subject to the Yahoo! Terms of> > 
Service.> > >> > >> > >> > 
>     Your use of Yahoo! Groups is subject to the 
Yahoo! Terms of> > Service.> > >> > 
>> > >         
Yahoo! Groups Sponsor> > 
>               
ADVERTISEMENT> > >> > >> > >> 
> >> > >   Your use of Yahoo! Groups is subject 
to the Yahoo! Terms of> > Service.> >> 
>> >> >> >> > Your use of Yahoo! 
Groups is subject to <A 
href="">http://docs.yahoo.com/info/terms/> 
>> >> >> >> >> 
>> >> >> >> > Your use of Yahoo! 
Groups is subject to <A 
href="">http://docs.yahoo.com/info/terms/> 
>> >>>>>>> Your use 
of Yahoo! Groups is subject to <A 
href="">http://docs.yahoo.com/info/terms/>>>------------------------ 
Yahoo! Groups Sponsor ---------------------~-->Buy Stock for 
$4and no minimums.FREE Money 2002.<A 
href="">http://us.click.yahoo.com/k6cvND/n97DAA/ySSFAA/GHeqlB/TM---------------------------------------------------------------------~-> Your 
use of Yahoo! Groups is subject to <A 
href="">http://docs.yahoo.com/info/terms/ 
Your 
use of Yahoo! Groups is subject to the <A 
href="">Yahoo! Terms of Service.