How to resolve the algorithm Extreme floating point values step by step in the AWK programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Extreme floating point values step by step in the AWK programming language
Table of Contents
Problem Statement
The IEEE floating point specification defines certain 'extreme' floating point values such as minus zero, -0.0, a value distinct from plus zero; not a number, NaN; and plus and minus infinity. The task is to use expressions involving other 'normal' floating point values in your language to calculate these, (and maybe other), extreme floating point values in your language and assign them to variables. Print the values of these variables if possible; and show some arithmetic with these values and variables. If your language can directly enter these extreme floating point values then show it.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Extreme floating point values step by step in the AWK programming language
Source code in the awk programming language
BEGIN {
# This requires 1e400 to overflow to infinity.
nzero = -0
nan = 0 * 1e400
pinf = 1e400
ninf = -1e400
print "nzero =", nzero
print "nan =", nan
print "pinf =", pinf
print "ninf =", ninf
print
# When y == 0, sign of x decides if atan2(y, x) is 0 or pi.
print "atan2(0, 0) =", atan2(0, 0)
print "atan2(0, pinf) =", atan2(0, pinf)
print "atan2(0, nzero) =", atan2(0, nzero)
print "atan2(0, ninf) =", atan2(0, ninf)
print
# From least to most: ninf, -1e200, 1e200, pinf.
print "ninf * -1 =", ninf * -1
print "pinf * -1 =", pinf * -1
print "-1e200 > ninf?", (-1e200 > ninf) ? "yes" : "no"
print "1e200 < pinf?", (1e200 < pinf) ? "yes" : "no"
print
# NaN spreads from input to output.
print "nan test:", (1 + 2 * 3 - 4) / (-5.6e7 + nan)
# NaN never equals anything. These tests should print "no".
print "nan == nan?", (nan == nan) ? "yes" : "no"
print "nan == 42?", (nan == 42) ? "yes" : "no"
}
You may also check:How to resolve the algorithm Subtractive generator step by step in the ooREXX programming language
You may also check:How to resolve the algorithm Problem of Apollonius step by step in the Perl programming language
You may also check:How to resolve the algorithm Sorting algorithms/Quicksort step by step in the AArch64 Assembly programming language
You may also check:How to resolve the algorithm Singly-linked list/Element definition step by step in the Diego programming language
You may also check:How to resolve the algorithm Hello world/Standard error step by step in the Scilab programming language