strange ksh arithmetic


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting strange ksh arithmetic
# 15  
Old 02-04-2009
Hi.
Quote:
Originally Posted by cfajohnson

That was all you needed to post.
I am trying to help the OP solve his problem in an efficient way, so it makes sense to me to post the heart of his code with a correction that makes it work. If that can be done with a change of variable name, that seems easier than changing to the POSIX evaluation. He may still want to change to POSIX as his schedule allows, but most people need to get work done. The last part of the code is to show how using the string nan as a variable does not do what we might expect.
Quote:

On my version of ksh93 (as well as pdksh and bash) that code prints 0 for both cases.
Same here for pdksh and bash, as well as zsh -- at least for all versions under which I ran the script s4.
Quote:

I cannot reproduce the problem. What version of ksh93 are you using?
As noted in the listing of OS and command versions in the output, that was done with ksh 93s+. As noted in post #9, the nan issue is present in 93s and 93t.

Best wishes ... cheers, drl
# 16  
Old 02-04-2009
"ksh93 performs all calculations using the double precision floating point arithmetic type on your system." The New Kornshell Command and Programming Language by Bolsky and Korn.

So now you need to understand floating point arithmetic. If it's ieee floating point, +NaN, -NaN, +Inf, and -Inf must be supported. ksh93 has been stumbling on those constants, but the intent is to support ieee as fully as your system does.

NaN = not a number
Inf = infinity

In the ksh mailing list, they are always spelled NaN and Inf, I don't know if the all lower case spelling is considered to be acceptable. Some systems, and Cray comes very quickly to mind, do not support ieee floating point and cannot deal with NaN and Inf.

This is about all I know about nan and ksh93, so I can't shed much more light.

See this thread: https://mailman.research.att.com/pip...q4/001468.html
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh Arithmetic syntax error while comparing decimal numbers

Hello, I am having a problem when i execute following script on RHEL 6.4. Same script works fine on another machine where I have same version of RHEL and KSH. Below is the rpm and RHEL version. ossvm12(0)> rpm -qa | grep ksh ksh-20100621-19.el6.x86_64 ossvm12(0)> cat... (7 Replies)
Discussion started by: Adithya Gokhale
7 Replies

2. Shell Programming and Scripting

ksh vs perl strange interaction.

Hello everybody, I isolated an issue: please try the following script (under AIX) #!/usr/bin/ksh93 echo "Before Perl: \c" read line echo "|$line|" perl -e 'print "Perl invocation";' echo echo "After Perl: \c" read line echo "|$line|" On the first input, type Ctrl-D. It works... (13 Replies)
Discussion started by: jlovi
13 Replies

3. Shell Programming and Scripting

Arithmetic operations in bash,ksh,sh

Guys, The below expression is valid in which shells (sh,ksh,bash,csh)? VAR1=2 VAR2=$(($VAR1 -2)) Thanks (1 Reply)
Discussion started by: rprajendran
1 Replies

4. UNIX for Dummies Questions & Answers

Arithmetic: how to??

Hello all, I'd like to know how to perform arithmetic on multiple files. I have got many tab-delimited files. Each file contains about 2000 rows and 2000 columns. What I want to do is to to sum the values in each row & column in every file. The following explains what I want to do; ... (9 Replies)
Discussion started by: Muhammad Rahiz
9 Replies

5. Shell Programming and Scripting

ksh-script "arithmetic syntax error" comparing strings

Hi all, Iīve already searched the forum but canīt find what i am doing wrong. I am trying to compare two variables using ksh under red hat. The error I get is: -ksh: .: MDA=`md5sum /tmp/ftp_dir_after_transfer | cut -d' ' -f1 ` MDB=`md5sum /tmp/ftp_dir_before_transfer | cut -d' ' -f1 `... (3 Replies)
Discussion started by: old_mike
3 Replies

6. UNIX for Advanced & Expert Users

Strange KSH behaviour - any comments?

As you are probably aware, $# indicates the number of parameters passed into a korn shell script. But this appears to hang around for sunsequent runs...???? A simple script:- #!/usr/bin/ksh echo "#parameters $#" echo "\$1 $1" echo "\$2 $2" I run the script with 0 parameters (all fine) #... (7 Replies)
Discussion started by: gsw_aix
7 Replies

7. UNIX for Dummies Questions & Answers

Longer commands and strange behaviour on ksh

Hi, I was trying to customize this archaic HP-UX box. only shell available is ksh and that too seems to be pretty old and doesn't completely conform to what I read on the web about ksh. Anyway here are my issues: - I wanted to have a dynamic title on xterm or dtterm. I put the following lines... (2 Replies)
Discussion started by: anurags
2 Replies

8. Shell Programming and Scripting

Strange parameter passing problems (KSH)

Hi all, I'm having a rather peculiar problem involving parameter passing with declared functions in my shell script. Hope to get some advice here. A brief description of my code is as follows: However, I'm not getting the results I wanted. If I pass in $rdir, I'm going to end up... (4 Replies)
Discussion started by: rockysfr
4 Replies

9. Shell Programming and Scripting

arithmetic in ksh

Helloo.. I am trying one very simple thing I could not find anything on google.. I have 2 integer variable..and I need to do division...in ksh where $catch and $num are integer variable.. I tryed with this: printf "%0.2f" $final=$catch/$num but it does not work.. any help is... (12 Replies)
Discussion started by: amon
12 Replies

10. Shell Programming and Scripting

Strange behavior from 'read' statements. (ksh - but could be same on other shells)

I'm getting rather frustrated with an interactive script I'm writing. The script is divided up, with section for setting variable at the top, then functions (which make up most of the script) then basically a line at the end which calls the first function- the program moves between the... (5 Replies)
Discussion started by: alexop
5 Replies
Login or Register to Ask a Question