Sponsored Content
Top Forums Shell Programming and Scripting Need help in using power function in Bash Post 302178611 by ahjiefreak on Wednesday 26th of March 2008 02:52:29 AM
Old 03-26-2008
Need help in using power function in Bash

Hi,

I would like to use a power function in Bash in an awk '{ } .
e.g pow(2,3)=8

Any suggestion? I try to find online resources but most of them stated by using BC.

Please advise. Thanks.
 

9 More Discussions You Might Find Interesting

1. Programming

power function in C

Hi, I wrote a small program to find 2 to the power of 3, when I tried to execute the following error occured. How can I solve this problem? $ cat t1.c #include <math.h> #include<stdio.h> main() { int a=2; int b=3; int c; c = a ^ b; /* if i use ** instead of ^ also the same problem... (2 Replies)
Discussion started by: krishna
2 Replies

2. Shell Programming and Scripting

Need assistance with bash function

Hi all! I need a little help with an imbedded fuction I am trying to write. What I am trying to do is go to a series of hosts and get the contents of an XML file, storing some of the data, along with the name of the host it was gathered from. My intent is to store this in an array for later... (1 Reply)
Discussion started by: _jade_
1 Replies

3. Shell Programming and Scripting

bash search function

I want to have a function with a similar interface: search *.cpp asdf that will search recursively all directories for *.cpp file, containing line 'asdf' inside. I tried this: function search { find . -name "$1" | xargs grep -li $2; } But it doesn't work all the time. For example, if i run it... (3 Replies)
Discussion started by: doze
3 Replies

4. Shell Programming and Scripting

BASH function error

Hey everyone. I am currently testing my first function based BASH script. The ultimate goal is going to be moving logs from point A to point B (or if B is down, to point C). Part of this involves the following function: function testAlive{ ping -c 1 -q $1 } Now when I run ping -c... (1 Reply)
Discussion started by: msarro
1 Replies

5. Shell Programming and Scripting

Bash function

startvm() { startguest } Is there a way use one line to get this ? actually I want startvm=startguest (5 Replies)
Discussion started by: yanglei_fage
5 Replies

6. UNIX for Dummies Questions & Answers

Bash INKEY$ function...

This is probably common knowledge to the professionals but not so much for amateurs like myself. This is a code snippet for the equivalent of BASIC's... LET char$=INKEY$ As the timeout parameter cannot be less than 1 second then this is the only limitation... It is a single line... (5 Replies)
Discussion started by: wisecracker
5 Replies

7. Shell Programming and Scripting

Yes or No selection within bash function

I need to add a selection within the bash function below and am having some trouble doing so. phox2b() { printf "\n\n" printf "What is the id of the patient getting Phox2B analysis : "; read id printf "Is this an intronic variant? Y/N "; read match_choice case... (5 Replies)
Discussion started by: cmccabe
5 Replies

8. Shell Programming and Scripting

Bash function, for BSD

I am putting this thread to shell-threads, because it is about how to make a function work properly. I need a hint for declaring a function right, it has been more than a year I did not work that straight with bash. So my aim is to turn off the eth0 (as it would be in linux, and bge0 in bsd ),... (2 Replies)
Discussion started by: 1in10
2 Replies

9. Shell Programming and Scripting

Bash function problem

I am trying to figure out why I am having a "problem" with some functions in a bash script I am running. The reason for air quoting is that the functions are working, they are just not displaying anything to screen when called from another function. Here's an example: function Create_Input {... (6 Replies)
Discussion started by: dagamier
6 Replies
pow(3M) 						  Mathematical Library Functions						   pow(3M)

NAME
pow, powf, powl - power function SYNOPSIS
c99 [ flag... ] file... -lm [ library... ] #include <math.h> double pow(double x, double y); float powf(float x, float y); long double powl(long double x, long double y); cc [ flag... ] file... -lm [ library... ] #include <math.h> double pow(double x, double y); float powf(float x, float y); long double powl(long double x, long double y); DESCRIPTION
These functions compute the value of x raised to the power y, x^y>. If x is negative, y must be an integer value. RETURN VALUES
Upon successful completion, these functions return the value of x raised to the power y. For finite values of x < 0, and finite non-integer values of y, a domain error occurs and either a NaN (if representable), or an implemen- tation-defined value is returned. If the correct value would cause overflow, a range error occurs and pow(), powf(), and powl() return HUGE_VAL, HUGE_VALF, and HUGE_VALL, respectively. If x or y is a NaN, a NaN is returned unless: o If x is +1 and y is NaN and the application was compiled with the c99 compiler driver and is therefore SUSv3-conforming (see standards(5)), 1.0 is returned. o For any value of x (including NaN), if y is +0, 1.0 is returned. For any odd integer value of y > 0, if x is +-0, +-0 is returned. For y > 0 and not an odd integer, if x is +-0, +0 is returned. If x is +-1 and y is +-Inf, and the application was compiled with the cc compiler driver, NaN is returned. If, however, the application was compiled with the c99 compiler driver and is therefore SUSv3-conforming (seestandards(5)), 1.0 is returned. For |x| < 1, if y is -Inf, +Inf is returned. For |x| > 1, if y is -Inf, +0 is returned. For |x| < 1, if y is +Inf, +0 is returned. For |x| > 1, if y is +Inf, +Inf is returned. For y an odd integer < 0, if x is -Inf, -0 is returned. For y < 0 and not an odd integer, if x is -Inf, +0 is returned. For y an odd integer > 0, if x is -Inf, -Inf is returned. For y > 0 and not an odd integer, if x is -Inf, +Inf is returned. For y < 0, if x is +Inf, +0 is returned. For y > 0, if x is +Inf, +Inf is returned. For y an odd integer < 0, if x is +-0, a pole error occurs and +-HUGE_VAL, +-HUGE_VALF, and +-HUGE_VALL are returned for pow(), powf(), and powl(), respectively. For y < 0 and not an odd integer, if x is +-0, a pole error occurs and HUGE_VAL, HUGE_VALF, and HUGE_VALL are returned for pow(), powf(), and powl(), respectively. For exceptional cases, matherr(3M) tabulates the values to be returned by pow() as specified by SVID3 and XPG3. ERRORS
These functions will fail if: Domain Error The value of x is negative and y is a finite non-integer. If the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, the invalid floating-point exception is raised. The pow() function sets errno to EDOM if the value of x is negative and y is non-integral. Pole Error The value of x is 0 and y is negative. If the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, the divide-by-zero floating-point exception is raised. Range Error The result overflows. If the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, the overflow floating-point exception is raised. The pow() function sets errno to EDOM if the value to be returned would cause overflow. USAGE
An application wanting to check for exceptions should call feclearexcept(FE_ALL_EXCEPT) before calling these functions. On return, if fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an exception has been raised. An application should either examine the return value or check the floating point exception flags to detect exceptions. An application can also set errno to 0 before calling pow(). On return, if errno is non-zero, an error has occurred. The powf() and powl() functions do not set errno. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
exp(3M), feclearexcept(3M), fetestexcept(3M), isnan(3M), math.h(3HEAD), matherr(3M), attributes(5), standards(5) NOTES
Prior to Solaris 2.6, there was a conflict between the pow() function in this library and the pow() function in the libmp library. This conflict was resolved by prepending mp_ to all functions in the libmp library. See mp(3MP) for more information. SunOS 5.11 12 Jul 2006 pow(3M)
All times are GMT -4. The time now is 08:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy