Sponsored Content
Top Forums Shell Programming and Scripting Arithmetic calculations in bash file Post 302774903 by Don Cragun on Sunday 3rd of March 2013 07:43:02 PM
Old 03-03-2013
Quote:
Originally Posted by kristinu
I have 2 numbers

Code:
xmin = 0.369000018
xmax = 0.569000006

and want to calculate

Code:
(xmax- xmin) / 5.0

I have tried using $(( )) but is always giving an error
The bash shell doesn't perform non-integer arithmetic.
You can do it with a recent (newer than 1988) Korn shell:
Code:
xmin=0.369000018
xmax=0.569000006
printf "%.10f\n" $(( (xmax - xmin) / 5.0))

which produces:
Code:
0.0399999976

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Non-integer calculations in bash

I'm new at scripting but I thought I was getting pretty good at it. I've hit a snag. I try to use expr to compute a fraction say: expr 3 / 4, and I'm getting zero. I guess it's just truncating to the integer, in this case 0, but I need the decimal 0.75. What can I do to compute this value in... (2 Replies)
Discussion started by: jeriryan87
2 Replies

2. Shell Programming and Scripting

any way to speed up calculations in bash script

hi i have a script that is taking the difference of multiple columns in a file from a value from a single row..so far i have a loop to do that.. all the data is floating point..fin has the difference between array1 and array2..array1 has 700 x 300= 210000 values and array2 has 700 values.. ... (11 Replies)
Discussion started by: npatwardhan
11 Replies

3. Shell Programming and Scripting

Need help is manipulating a file with some arithmetic operations using bash script

Friends, I have a file with contents like: interface Serial0/4/0/0/1/1/1/1:0 encapsulation mfr multilink group 101 Now I need to manipulate the file in such a way that to all the numbers less than 163, 63 gets added and to all numbers greater than 163, 63 gets deducted.(The numbers... (2 Replies)
Discussion started by: shrijith1
2 Replies

4. Shell Programming and Scripting

calculations in bash

HI i have following problem, i need to use split command to split files each should be cca 700 lines but i dont know how to inplement it in the scripts becasuse each time the origin file will be various size , any body got any idea cheers (2 Replies)
Discussion started by: kvok
2 Replies

5. 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

6. Shell Programming and Scripting

bash script range calculations

Hi, I have data in the following form: AB001 10 AB002 9 AB003 9 etc AB200 5 What I need to do is sum up the second value according to groups of the first, i.e. AB001 to AB030 the total being X, AB031 to AB050 the total being Y etc (there are 5 AB ranges of different sizes). I'm sure... (3 Replies)
Discussion started by: chrissycc
3 Replies

7. Shell Programming and Scripting

Help with Arithmetic calculations in Shell script

Hi, I need a help with arithmetic calculations in my script. I have two variables: a=17; b=1712 I want to perform ($a/$b)*100 with two decimals in the result. I tried with following: res=$((100*a/b)) res=`echo "scale=2; $a / $b" | bc` But I am not getting the decimal values.... (4 Replies)
Discussion started by: karumudi7
4 Replies

8. Shell Programming and Scripting

Arithmetic on a Float in bash

I am using bash I have a script that takes a number, i.e. 85.152, which is always a non integer and essentially tries to get that number to be a multiple of 10. My code is as follows: number=85.152 A=${number%.*} #Converts float to integer typeset -i B=$(((A-20)/10)) #subtracting 20 is... (12 Replies)
Discussion started by: prodigious8
12 Replies

9. Shell Programming and Scripting

Bash arithmetic issue

I found the following issue by simply increasing a variable. The ((A++)) expression returns an error, the other expressions both return 0. Does anyone know why? script.sh: #! /bin/bash A=0 B=0 C=0 ((A++)) ; echo "${?}" ((B=B+1)) ; echo "${?}" ((C+=1))... (8 Replies)
Discussion started by: elbrand
8 Replies

10. Shell Programming and Scripting

Arithmetic with bash

I need to divide the number of white spaces by total number of characters in a file using bash. I am able to get the number of white spaces correctly using: tr -cd < afile | wc -c I am also able to get the total number of characters using: wc -c afile How do I divide the first... (2 Replies)
Discussion started by: ngabrani
2 Replies
PLSVPA(3plplot) 						    PLplot API							   PLSVPA(3plplot)

NAME
plsvpa - Specify viewport in absolute coordinates SYNOPSIS
plsvpa(xmin, xmax, ymin, ymax) DESCRIPTION
Alternate routine to plvpor(3plplot) for setting up the viewport. This routine should be used only if the viewport is required to have a definite size in millimeters. The routine plgspa(3plplot) is useful for finding out the size of the current subpage. Redacted form: plsvpa(xmin, xmax, ymin, ymax) This function is used in example 10. ARGUMENTS
xmin (PLFLT, input) The distance of the left-hand edge of the viewport from the left-hand edge of the subpage in millimeters. xmax (PLFLT, input) The distance of the right-hand edge of the viewport from the left-hand edge of the subpage in millimeters. ymin (PLFLT, input) The distance of the bottom edge of the viewport from the bottom edge of the subpage in millimeters. ymax (PLFLT, input) The distance of the top edge of the viewport from the bottom edge of the subpage in millimeters. AUTHORS
Geoffrey Furnish and Maurice LeBrun wrote and maintain PLplot. This man page was automatically generated from the DocBook source of the PLplot documentation, maintained by Alan W. Irwin and Rafael Laboissiere. SEE ALSO
PLplot documentation at http://plplot.sourceforge.net/resources. August, 2012 PLSVPA(3plplot)
All times are GMT -4. The time now is 11:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy