Mailinglist Archive: opensuse (1690 mails)

< Previous Next >
Re: [opensuse] c - Segmentation fault on 11.4 - need help figuring out (strtod?)
Hello,

On Thu, 03 Nov 2011, Patrick Shanahan wrote:
There are also mathomatic builds available that will suffice.

And bc.

### 4*a(1) = pi, libm (bc -l) is needed for the a() function.
for i in 5 7 4 16 ; do
printf "r: %2s area: %7.3f\n" $i $(echo "$i^2 * 4*a(1);" | bc -l)
done

and perl:

perl -w -e '
use strict; use Math::Trig qw(:pi);
for( 5, 7, 4, 16 ) {
printf("r: %2s area: %7.3f\n", $_, pi * $_ ** 2);
}'

or the full version:

==== area.pl ====
#!/usr/bin/perl
use warnings; use strict; use Math::Trig qw(:pi);
foreach(@ARGV) {
next unless /^-?\d+\.?\d*$/;
printf("r: %2s area: %7.3f\n", $_, pi * $_ ** 2);
}
====

$ perl area.pl 1 2 3 dog 4 5

GNU awk:

==== area.awk
#!/usr/bin/gawk -f
BEGIN {
pi = 4 * atan2(1,1);
for( a = 0; a < ARGC; a++ ) {
if( i = strtonum(ARGV[a]) ) {
printf("r: %2s area: %7.3f\n", i, i^2 * pi);
}
}
}
====

perl area.awk 1 2 3 dog 4 5

and then there's:

for i in 1 2 3 dog 4 5 7 16; do units "pi $i^2"; done

or

for i in 1 2 3 dog 4 5 7 16; do units "circlearea(${i} m)"; done

HTH,
-dnh

--
Every fleeting thought you've ever had in your life, no matter how bizarre,
is someone's lifelong obsession. And he has a website.
-- Skif's Internet Theorem
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse+owner@xxxxxxxxxxxx

< Previous Next >