🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

5 total messages Started by Captain Neptune Sun, 17 May 1987 23:05
pow(3M) may have a bug or undocumented limitation
#537
Author: Captain Neptune
Date: Sun, 17 May 1987 23:05
20 lines
1755 bytes
I am running an HP 9000/840 running HP-UX and I have a problem doing some math.
I am trying to use pow(3M) to raise a positive integer value to a negative
integer value.  For example, the 12th root of 2 --> 2 ^ (-12) --> pow(2,-12).

I keep getting "DOMAIN error" even though the manual page doesn't seem to
cite this case as an illegal one.  It would be illegal if, say, the first
argument was zero, for instance.  Pow(3M) is found on the manual page for
"exp(3M)".

Any ideas why this is happening?  Have I made some fundamental blunder?
Has pow(3M) made some fundamental blunder?
-- 
+----------------------------------------------------------------------------+
|     Mark Steven Jeghers: the terrorist smuggling CIA weapons to Libya      |
|                                                                            |
|     {ihnp4,cbosgd,lll-lcc,lll-crg}|{dual,ptsfa}!cogent!mark                |
|                                                                            |
|     Standard Disclaimer:  Contents may have settled during shipment.       |
+----------------------------------------------------------------------------+
Re: pow(3M) may have a bug or undocumented limitation
#538
Author: Ron Ueberschaer
Date: Mon, 18 May 1987 04:35
26 lines
1460 bytes
> [problem with doing]  pow(2, -12)
When passing integer arguments to pow(), or any other
math function requiring floating points (double, actually),
be sure that you either cast the variable, e.g.

	pow((double) i, (double) j)    ,

or explicitely type the decimal point, e.g.

	pow(2., -12.)    .

While most compilers handle implicit type conversion in
*expressions*, arguments to *functions* require more care.

The particular problem you are having bit me once before,
although I didn't get a useful runtime error message, just
the old "(core dumped)."  I don't think the negative exponent
is the problem.  A negative mantissa, however, will not work,
even if the exponent is integer.

			Hope this helps,

			Ron Ueberschaer		
			SRI International 	Menlo Park, CA
			...!{hplabs,rutgers}!sri-unix!ubi
			ubi@sri-unix.UUCP
Re: pow(3M) may have a bug or undocumented limitation
#539
Author: tj
Date: Mon, 18 May 1987 17:33
25 lines
1768 bytes
In article <226@cogent.UUCP>, mark@cogent.UUCP (Captain Neptune) writes:
> 
> I am running an HP 9000/840 running HP-UX and I have a problem doing some math.
> I am trying to use pow(3M) to raise a positive integer value to a negative
> integer value.  For example, the 12th root of 2 --> 2 ^ (-12) --> pow(2,-12).
> 
> I keep getting "DOMAIN error" even though the manual page doesn't seem to
> cite this case as an illegal one.  It would be illegal if, say, the first
> argument was zero, for instance.  Pow(3M) is found on the manual page for
> "exp(3M)".

My guess is that you have neglected ensure that the arguments passed to pow
are doubles. try pow(2.0, -12.0);
BTW the 12th root of 2 is 2^(1/12) i.e. pow(2.0, 1.0/12.0);

V7 and BSD man page say that pow gives domain error when 2nd argument
is negative and non-integral. This is wrong. SYSV man page correctly
states that domain error results when 1st arg is negative and 2nd is
non-integral.

-- 
     ll  // // ,~/~~\'   T. J. Thompson {decvax,ihnp4,seismo}!watmath!mks!tj
    /ll/// //l' `\\\     Mortice Kern Systems Inc.
   / l //_// ll\___/     43 Bridgeport Rd. E., Waterloo, ON, Can. N2J 2J4
O_/                      (519)884-2251
Re: pow(3M) may have a bug or undocumented limitation
#540
Author: d.gertler
Date: Mon, 18 May 1987 18:11
9 lines
996 bytes
+ In article <226@cogent.UUCP> mark@cogent.UUCP (Captain Neptune) writes:
+    [...]
+ integer value.  For example, the 12th root of 2 --> 2 ^ (-12) --> pow(2,-12).
+    [...]
+   Have I made some fundamental blunder?

Yes.  2^(-12) is *NOT* the 12th root of 2.  It is the 12th power of 1/2.
[As for the matter at hand, your pow(3M) problem, I have no answer.  Sorry,
but I couldn't let this one go by.]
Re: pow(3M) may have a bug or undocumented limitation
#541
Author: John Worley
Date: Tue, 19 May 1987 01:48
21 lines
1281 bytes
> I am trying to use pow(3M) to raise a positive integer value to a negative
> integer value.  For example, the 12th root of 2 --> 2 ^ (-12) --> pow(2,-12).
> 
> Any ideas why this is happening?  Have I made some fundamental blunder?
> Has pow(3M) made some fundamental blunder?

    You have made two fundamental blunders.  First, the arguments to pow() are
doubles, so the correct way to all the function is:

	pow(2.0, -12.0);

   The second blunder is that 2 ^ -12 == 1 / (2 ^ 12), NOT 12th-root 2!  The
code for that would be:

	pow(2.0, 1.0 / 12.0);

    I suggest using 2^-12 would generate a useless musical scale (the only
practical application of 12-th root 2 I know about).

					John Worley
					hplabs!dana!worley
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads