Shell does not give you decimal points. You can multiply ahead to get what you want, though, if you know the result will be 0-99 and not above.
Code:
$ printf "0.%02d\n" $(( (a*10000) / b ))
0.99
$
You forgot the multiply by 100 in your bc statement, so your answer is 0.0099, not 0.99. Do that first in your bc statement (i.e. multiply a by 100, not the result of a/b) and it works fine.
Lastly, the way to avoid divide-by-zero errors is to not divide by zero Check your values before you calculate.
Last edited by Corona688; 09-13-2012 at 02:04 PM..
I am trying to do a shell script to monitor if any files went through in the last hour.
There is a script in cron that runs every sec checking to see if a file is there and ftp the file out of this folder.
Now I just want to add a block of code that will check to see no files went in the last... (3 Replies)
I am writting a script in the ksh shell and am trying to find a way to report the total execution time of the script without requiring the user to specify the time function when executing the script.
Does anyone have any examples they have used. I have been setting up two date variables (one at... (1 Reply)
I am begining to learn bourne shell and as a practice I have written a script which when given the purchase price and percentage of discount calculates the savings.
I somehow cannot figure out why my script fails to do arthimatic calculation on real numbers.
Could anyone look at the script... (5 Replies)
Hello everybody,
I decided to take a Unix Introduction class and have never had experience with programming. Everything was fine until recently when the Prof. started shell scripting and he wants us to make a small script to add unlimited numbers from arguments and from standard input.
I... (1 Reply)
Hello everybody,
I decided to take a Unix Introduction class and have never had experience with programming. Everything was fine until recently when the Prof. started shell scripting and he wants us to make a small script to add unlimited numbers from arguments and from standard input.
I... (8 Replies)
Hi all,
Thanks in Advance , i am very new to programming part in script i think using some caluations+ sed command only we can do this process in script.
for exampl:
i have file in that one line is like this
using sed i can replace the date and all but my requirement is
The... (3 Replies)
I have 2 numbers
xmin = 0.369000018
xmax = 0.569000006
and want to calculate
(xmax- xmin) / 5.0
I have tried using $(( )) but is always giving an error (8 Replies)
Dear All,
I read some variables in a file and assigned as name for each of them.
If I do echo I am able to see the values as 1.0E-05,3.4,5.0E-03 etc,
Now I want to do some mathematical operations with them.
Lets say
1
1.0E-05*5.0E-03
expected ans is 5.0E-08
2
1.0E-05/5.0E-03
expected... (9 Replies)
Discussion started by: linuxUser_
9 Replies
LEARN ABOUT HPUX
fmaw
fma(3M)fma(3M)NAME
fma(), fmaf(), fmaw(), fmal(), fmaq() - floating multiply-add functions
SYNOPSIS DESCRIPTION
returns (x*y) + z, rounded as one ternary operation: it computes the value (as if) to infinite precision and rounds once to the result
format, according to the current rounding mode.
is a version of it takes arguments and returns a result.
is a version of it takes arguments and returns a result.
is an version of it takes arguments and returns an result.
is equivalent to on HP-UX systems.
The and macros are defined in indicating that are each as fast as a multiply and add.
USAGE
These functions are available only for Integrity servers.
To use these functions, compile either with the default option or with the and options.
To use or compile also with the option.
To use these functions, make sure your program includes Link in the math library by specifying on the compiler or linker command line.
RETURN VALUE
If one of x and y is infinite, the other is zero, and z is a NaN, returns NaN and optionally raises the invalid exception.
If one of x and y is infinite, the other is zero, and z is not a NaN, returns NaN and raises the invalid exception.
If x times y is an exact infinity and z is also an infinity but with the opposite sign, returns NaN and raises the invalid exception.
returns a properly signed infinity in lieu of a value whose magnitude is too large, and raise the overflow and inexact exceptions.
raises the underflow and inexact exceptions whenever a result is tiny (essentially denormal or zero) and thereby suffers loss of accuracy,
and may raise those exceptions if the result is merely tiny.
raises the inexact exception whenever a rounded result does not equal the mathematical result.
ERRORS
No errors are defined.
SEE ALSO math(5).
STANDARDS CONFORMANCE
: ISO/IEC C99 (including Annex F, ``IEC 60559 floating-point arithmetic'')
HP Integrity Server Only fma(3M)