Real constants and functions: Difference between revisions
Content added Content deleted
(→{{header|BASIC}}: + AWK) |
(→{{header|AWK}}: added Pi) |
||
Line 49: | Line 49: | ||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
The following scriptlets demonstrate some of the required items. ''abs()'' was trivially implemented. Missing are: |
The following scriptlets demonstrate some of the required items. ''abs()'' was trivially implemented. Missing are: |
||
* Pi |
|||
* ''floor(), ceil()'' -- could be easily implemented as well |
* ''floor(), ceil()'' -- could be easily implemented as well |
||
The ''pow()'' example is from [[Exponentiation operator]]. |
The ''pow()'' example is from [[Exponentiation operator]]. |
||
<lang>$ awk 'func abs(x){return(x<0?-x:x)}BEGIN{print exp(1),sqrt(2),log(2),abs(-42)}' |
<lang>$ awk 'func abs(x){return(x<0?-x:x)}BEGIN{print exp(1),atan2(1,1)*4,sqrt(2),log(2),abs(-42)}' |
||
2.71828 1.41421 0.693147 42 |
2.71828 3.14159 1.41421 0.693147 42 |
||
$ awk 'func pow(x,n){r=1;for(i=0;i<n;i++)r=r*x;return r}{print pow($1,$2)}' |
$ awk 'func pow(x,n){r=1;for(i=0;i<n;i++)r=r*x;return r}{print pow($1,$2)}' |