How to resolve the algorithm Real constants and functions step by step in the AWK programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Real constants and functions step by step in the AWK programming language
Table of Contents
Problem Statement
Show how to use the following math constants and functions in your language (if not available, note it):
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Real constants and functions step by step in the AWK programming language
Source code in the awk programming language
BEGIN {
print sqrt(2) # square root
print log(2) # logarithm base e
print exp(2) # exponential
print 2 ^ -3.4 # power
}
# outputs 1.41421, 0.693147, 7.38906, 0.0947323
BEGIN {
E = exp(1)
PI = atan2(0, -1)
}
function abs(x) {
return x < 0 ? -x : x
}
function floor(x) {
y = int(x)
return y > x ? y - 1 : y
}
function ceil(x) {
y = int(x)
return y < x ? y + 1 : y
}
BEGIN {
print E
print PI
print abs(-3.4) # absolute value
print floor(-3.4) # floor
print ceil(-3.4) # ceiling
}
# outputs 2.71828, 3.14159, 3.4, -4, -3
You may also check:How to resolve the algorithm Loops/Nested step by step in the Fantom programming language
You may also check:How to resolve the algorithm Averages/Arithmetic mean step by step in the Lambdatalk programming language
You may also check:How to resolve the algorithm Vector products step by step in the jq programming language
You may also check:How to resolve the algorithm De Bruijn sequences step by step in the Julia programming language
You may also check:How to resolve the algorithm Ascending primes step by step in the JavaScript programming language