From 615289b57e4b22f24ea873cc2f6274d6cbbdd4ad Mon Sep 17 00:00:00 2001 From: tTh Date: Tue, 17 Sep 2024 18:55:04 +0200 Subject: [PATCH] functions demonstartor --- code/awk/demo-func.awk | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 code/awk/demo-func.awk diff --git a/code/awk/demo-func.awk b/code/awk/demo-func.awk new file mode 100755 index 0000000..dbcb1bf --- /dev/null +++ b/code/awk/demo-func.awk @@ -0,0 +1,20 @@ +#!/usr/bin/awk -f +BEGIN { + print "---- demo fonction ----" + print_sinus(1.0) + print_dist(0.5, 0.5, 0.0) + } + +# the simple version +function print_sinus ( value ) +{ +printf "sin(%f) = %f\n", value, sin(value) +} + +# version with local variables. +function print_dist(x, y, z, dist) +{ +dist = sqrt(x*x + y*y + z*z) +printf "distance from center = %f\n", dist +} +