01-24-2011
Because Bash (and most other shells) don't know any mathematical operations or functions beyond the basic five (add, sub, mul, div, mod). If you need higher level functions, use bc or a different scripting language like Perl or Python.
This User Gave Thanks to pludi For This Post:
10 More Discussions You Might Find Interesting
1. Programming
Hi!
when i'm trying to compile this lite example
on my linux machine I'll get errors and i don't know why..
#include <stdio.h>
#include <math.h> /* needed by sqrt() */
int main()
{
printf("%f", sqrt(10.0));
return (0);
}
this is the error:
/tmp/cc33hNVHK.o: In function... (1 Reply)
Discussion started by: CreamHarry
1 Replies
2. Programming
I was writing a simple program in linux, which includes sqrt function of c.
I included the math.h. But when I use gcc to compile it, it gave an error message:
/home/murat/tmp/ccOv9upo.o(.text+0x4b): In function `main':
: undefined reference to `sqrt'
collect2: ld returned 1 exit status
I... (2 Replies)
Discussion started by: murataht
2 Replies
3. Shell Programming and Scripting
HI,
I have a file which i catenate and using the fields in the file, I would like to get sqrt of it. I tried to man the function but it normally would need an echo as well as bc.
What I am intending to find out is catenate a file where let say
cat a.txt| awk ' {
t= h*($3+$2);
t=... (7 Replies)
Discussion started by: ahjiefreak
7 Replies
4. Shell Programming and Scripting
hi,
i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies
5. Shell Programming and Scripting
hi friends
can any body tell me how can i find sqrt of a any given number without using expr in bash shell
while i am doing i got some errors please take a look
and code is here
x=$((( ( sqrt($1) ) | bc )))
echo $x
$ sh quadratic-eqn-roots.sh 9
quadratic-eqn-roots.sh: line 12: ( (... (6 Replies)
Discussion started by: srinivas2828
6 Replies
6. Programming
This so basic that it should work.... Any ideas would be appreciared. Using a number directly in the sqrt allows it to compile.
primrose > cat a.c
#include <stdio.h>
#include <math.h>
int main(void)
{
double abcd=9;
printf("%f\n",sqrt(abcd));
}
primrose > gcc a.c
Undefined first... (2 Replies)
Discussion started by: plastichead
2 Replies
7. Shell Programming and Scripting
In the bash below I am asking the user for a panel and reading that into bed. Then asking the user for a file and reading that into file1.Is the grep in bold the correct way to apply the selected panel to the file? I am getting a syntax error. Thank you :)
... (4 Replies)
Discussion started by: cmccabe
4 Replies
8. Shell Programming and Scripting
How to run several bash commands put in bash command line without needing and requiring a script file.
Because I'm actually a windows guy and new here so for illustration is sort of :
$ bash "echo ${PATH} & echo have a nice day!"
will do output, for example:... (4 Replies)
Discussion started by: abdulbadii
4 Replies
9. UNIX for Beginners Questions & Answers
In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed ? Is there any way to get the script names for the process command ?
--- Post updated at 08:39 AM ---
in KSH (Korn Shell), my command output shows the script names but when run in the Bash Shell... (3 Replies)
Discussion started by: i4ismail
3 Replies
10. Shell Programming and Scripting
Hi all...
This is just a fun project to see if it is possible to get a square root of a positive integer from 1 to 9200000 to 6 decimal places on a 64 bit architecture machine.
It is coded around dash and the results show the values from 0 to 10000.
Complex numbers can easily be catered for by... (3 Replies)
Discussion started by: wisecracker
3 Replies
ADD(2) System Calls Manual ADD(2)
NAME
add, sub, mul, div, raddp, rsubp, rmul, rdiv, rshift, inset, rcanon, eqpt, eqrect, ptinrect, rectinrect, rectXrect, rectclip, Dx, Dy, Pt,
Rect, Rpt - arithmetic on points and rectangles
SYNOPSIS
#include <u.h>
#include <libc.h>
#include <libg.h>
Point add(Point p, Point q)
Point sub(Point p, Point q)
Point mul(Point p, int a)
Point div(Point p, int a)
Rectangle raddp(Rectangle r, Point p)
Rectangle rsubp(Rectangle r, Point p)
Rectangle rmul(Rectangle r, int a)
Rectangle rdiv(Rectangle r, int a)
Rectangle rshift(Rectangle r, int a)
Rectangle inset(Rectangle r, int n)
Rectangle rcanon(Rectangle r)
int eqpt(Point p, Point q)
int eqrect(Rectangle r, Rectangle s)
int ptinrect(Point p, Rectangle r)
int rectinrect(Rectangle r, Rectangle s)
int rectXrect(Rectangle r, Rectangle s)
int rectclip(Rectangle *rp, Rectangle b)
int Dx(Rectangle r)
int Dy(Rectangle r)
Point Pt(int x, int y)
Rectangle Rect(int x0, int y0, int x1, int y1)
Rectangle Rpt(Point p, Point q)
DESCRIPTION
The functions Pt, Rect and Rpt construct geometrical data types from their components. These are implemented as macros.
Add returns the Point sum of its arguments: Pt(p.x+q.x, p.y+q.y). Sub returns the Point difference of its arguments: Pt(p.x-q.x, p.y-q.y).
Mul returns the Point Pt(p.x*a, p.y*a). Div returns the Point Pt(p.x/a, p.y/a).
Raddp returns the Rectangle Rect(add(r.min, p), add(r.max, p)); rsubp returns the Rectangle Rpt(sub(r.min, p), sub(r.max, p)). Rmul
returns the Rectangle Rpt(mul(r.min,a), mul(r.max,a)); Rdiv returns the Rectangle Rpt(div(r.min,a), div(r.max,a)).
Rshift returns the rectangle r with all coordinates either left-shifted or right-shifted by a, depending on whether a is positive or nega-
tive, respectively.
Inset returns the Rectangle Rect(r.min.x+n, r.min.y+n, r.max.x-n, r.max.y-n).
Rcanon returns a rectangle with the same extent as r, canonicalized so that min.x <= max.x, and min.y <= max.y.
Eqpt compares its argument Points and returns 0 if unequal, 1 if equal. Eqrect does the same for its argument Rectangles.
Ptinrect returns 1 if p is a point within r, and 0 otherwise.
Rectinrect returns 1 if all the pixels in r are also in s, and 0 otherwise.
RectXrect returns 1 if r and s share any point, and 0 otherwise.
Rectclip clips in place the Rectangle pointed to by rp so that it is completely contained within b. The return value is 1 if any part of
*rp is within b. Otherwise, the return value is 0 and *rp is unchanged.
The functions Dx and Dy give the width (x) and height (y) of a Rectangle. They are implemented as macros.
SOURCE
/sys/src/libg
SEE ALSO
graphics(2)
ADD(2)