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

Re: [amibroker] Modulus Operator and PI



PureBytes Links

Trading Reference Links


Hello,
 
There is an error in the the description of % 
operator.
In fact it uses internaly fmod() C-runtime library 
function for
performing operations. It means that it does not 
round the numbers
to nearest integers:
 
The fmod runtime function (and  x % y 
operator in AFL) calculates the floating-point remainder f of x / 
y such that x = i * y + f, where 
i is an integer, f has the same sign as x, and the absolute 
value of f is less than the absolute value of y.
 
 
Best regards,Tomasz 
Janeczko===============AmiBroker - the comprehensive share 
manager.<A 
href="">http://www.amibroker.com
<BLOCKQUOTE 
>
----- Original Message ----- 
<DIV 
>From: 
Dimitris 
Tsokakis 
To: <A title=amibroker@xxxxxxxxxxxxx 
href="">amibroker@xxxxxxxxxxxxxxx 
Sent: Wednesday, September 05, 2001 
8:17 PM
Subject: [amibroker] Modulus Operator 
and PI

 
Dear Tomasz,
The new 3.70 Help is very well prepared again. Tutorials for new items is 
the 
certainly the best way.
I noticed something not so clear in
 
Modulus operator
A new operator (%) - modulus (or remainder) was 
added:
result = number1 % number2
The modulus, or remainder, operator divides number1 by number2 

(rounding floating-point numbers to integers) and returns only 
the remainder as result. 
 
The plural "numbers" in the parenthesis may be translated that we round 

number1 and number2, then we divide and then take the remainder.
This would give 3.2%3.1==3%3==0, which is not the result of 
3.2%3.1.
As I saw, the procedure is 
3.2/3.1 gives 1.03
1.03 becomes 1 after rounding
3.2-3.1*1==0.1, which is the 3.2%3.1.
I saw that the generic formula behind % is
R1%R2==R1-R2*INT(R1/R2);
for positive, negative, integers or non-integers.
Is it O. K. ?
Please confirm.
Best regards
Dimitris Tsokakis
P. S. Please remember in some next edition to correct the typo in



EXAMPLE
The formula "atan( 1.00 )" returns PI/2
It is our only source for PI in AFL.
PI=4*atan(1);
 Your 
use of Yahoo! Groups is subject to the <A 
href="">Yahoo! Terms of Service.