Historical implementations of awk did not support floating-point infinities and NaNs in numeric strings; e.g., "-INF" and "NaN".
However, implementations that use the atof() or strtod() functions to do the conversion picked up support for these values
if they used a ISO/IEC 9899:1999 standard version of the function instead of a ISO/IEC 9899:1990 standard version.
Due to an oversight, the 2001 through 2004 editions of this standard did not allow support for infinities and NaNs,
but in this revision support is allowed (but not required). This is a silent change to the behavior of awk programs;
for example, in the POSIX locale the expression:
("-INF" + 0 < 0)
formerly had the value 0 because "-INF" converted to 0, but now it may have the value 0 or 1.
Code:
strtod recognizes four special input strings. The strings "inf" and "infinity" are converted to ∞,
or to the largest representable value if the floating-point format doesn’t support infinities.
You can prepend a "+" or "-" to specify the sign. Case is ignored when scanning these strings.
The strings "nan" and "nan(chars…)" are converted to NaN. Again, case is ignored.
If chars… are provided, they are used in some unspecified fashion to select a particular representation of NaN (there can be several).
When a math function suffers a domain error, it raises the invalid exception and returns NaN....
Code:
A valid floating point number for strtod using the "C" locale is formed by an optional sign character (+ or -), followed by one of:
...........
- INF or INFINITY (ignoring case).
- NAN or NANsequence (ignoring case), where sequence is a sequence of characters, where each character is either an alphanumeric character
some additional infos..
Code:
- NAN and INF expressions are defined in 'math.h' as double/floating/long double number to C locale *(C99/C11 standarts)
# define FP_NAN FP_NAN
# define FP_INFINITE FP_INFINITE
-- nawk uses "strtod" for convert the strings to double type
- executes "strtod" function and
+ returns 0.000000 double for "strings" and "strings/numbers" mix char sequence
+ returns number.000000 double for "numbers" and "numbers/strings" mix char sequence (cares only first numbers from the beginning )
+ returns NaN double for beginning the "nan" (ignore case) string
+ returns Inf double for beginning the "inf" (ignore case) string
- executes summ operations
see results :
'NaN + number' = NaN (Not a Number)
----------------------------------------------------------
# echo nAN1 | nawk '{print $1+1}'
NaN
# echo nAN1 | nawk '{print $1*1}'
NaN
# echo nAN1 | nawk '{print $^1}'
NaN
# echo nAN1 | nawk '{print $1-1}'
NaN
# echo nAN1 | nawk '{print $1/1}'
NaN'Inf + number' = Inf (infinity)
----------------------------------------------------------
# echo Inf1 | nawk '{print $1+1}'
Inf
# echo Inf1 | nawk '{print $1*1}'
Inf
# echo Inf1 | nawk '{print $1^1}'
Inf
# echo Inf1 | nawk '{print $1-1}'
Inf
# echo Inf1 | nawk '{print $1/1}'
Inf
Note : tested nawk on the SunOS 5.1 11.1 sun4v sparc
i'm new to shell scripting and have a problem please help me
in the script i have a nawk block which has a variable count
nawk{
.
.
.
count=count+1
print count
}
now i want to access the value of the count variable outside the awk block,like..
s=`expr count / m`
(m is... (5 Replies)
i'm puzzled....
trying to look for the pattern }"'. but the below code returns to me the message below (pattern is curley queue + dbl qt + sng qt + period)
nawk -v pat="\}\"\'\."'
{
if (match($0, pat)) {
before = substr($0,1,RSTART-1);
... (11 Replies)
Howdy experts,
We have some ranges of number which belongs to particual group as below.
GroupNo StartRange EndRange
Group0125 935300 935399
Group2006 935400 935476
937430 937459
Group0324 935477 935549
... (6 Replies)
Hello All,
I am having problem to find what is the smallest number from 90% of highest numbers from all numbers in file. I am having file with thousands of lines and hundreds of columns.
I am familiar mainly with bash but I am open to whatever suggestion witch will lead to the solutions.
If I... (11 Replies)
I need some help in generating pair of numbers in orders using FORTRAN code.
The order is like following.
loop_1: 1,2 2,3 3,4 4,5 5,6 6,7 7,8 ..... until <= 2000
loop_2: 1,3 3,5, 5,7 7,9 9,11 11,13 ........until <= 2000
loop_3: 1,4, 4,7 7,10 10,13 13,17 ..... until... (3 Replies)
Hi All,
This might be a basic question... I need to write a script to find all/any Speacial/Null/Control Chars and Print Line Numbers from an input file.
Output something like
Null Characters in File Name at : Line Numbers
Line = Print the line
Control Characters in File Name at : Line... (2 Replies)
Hi.. i am running nawk scripts on solaris system to get records of file1 not in file2 and find duplicate records in a while with the following scripts -compare
nawk 'NR==FNR{a++;next;} !a {print"line"FNR $0}' file1 file2duplicate - nawk '{a++}END{for(i in a){if(a-1)print i,a}}' file1in the middle... (12 Replies)
Hi All,
I want to keep the name of the songs with their respective extensions only.
Sample Code
========
03 Choti choti gaiya choti choti gaval.mp3
03---Brazil Dhol.mp3
03 PAYALIYA .mp3
04 - Isq Risk .mp3
04%20-%20Oh%20My%20Love(wapking.in).mp3
08 - A2 - Aasan Nahin Yahan .mp3
AE... (3 Replies)
I sux at this type of stuff. I have a huge wordlist. I want to get rid of everything in each word except the letters. I want to remove numbers and all special characters. And since this list was created using cewl I some how picked up something like so Latin characters and would like to remove them... (6 Replies)