[PD] Negative input numbers for [pow] return 0

Mon Apr 22 22:15:59 CEST 2013

```
If you think about it negative exponents require a completely
different algorithm that is discontinuous with the one for
positives. Instead of multiplying you divide n times.

b^-n = 1/b^n

Use a [moses] and two [pow], where the negative branch
then has its reciprocal, or use [abs] and [sgn] to flip
the negative ones through a reciprocal.

cheers,
Andy

On Mon, Apr 22, 2013 at 03:07:43PM +0100, Joe White wrote:
> >
> > > Is this a known limitation or bug?
> > it's most likely a feature that tries to protect you from things like:
> > [-1(
> > |
> > [pow 0.5]
> > |
>
>
> Ahh yeah makes sense.
>
> I'm not sure why but I always feel uneasy using [expr], maybe because of
> libpd :)
>
> [expr] does handle (-1)^0.5 with a NaN output though. Would it be possible
> to add this to [pow] as well? Something like for negative base values,
> non-integer exponent values would return NaN?
>
> Additionally for [pow] to output '0' seems wrong, because that is
> definitely not the answer. I've never seen NaN output elsewhere so I'm
> assuming [expr] outputs a symbol and not some Pd defined NaN type (maybe?).
>
> Thanks for the reply IOhannes!
>
> Cheers,
> Joe
>
> On 22 April 2013 13:30, IOhannes m zmoelnig <zmoelnig at iem.at> wrote:
>
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > On 2013-04-22 14:19, Joe White wrote:
> > > Hi,
> > >
> > > Just realised putting a negative number into the [pow] object
> > > outputs '0'?!?
> > >
> > > For example if I do:
> > >
> > > [-1 ( | [pow 2]
> > >
> > > it returns 0, where I would expect it to return 1.
> > >
> > > Is this a known limitation or bug?
> >
> > it's most likely a feature that tries to protect you from things like:
> >
> > [-1(
> > |
> > [pow 0.5]
> > |
> >
> > > Are there any work arounds if I want a variable power?
> >
> > urgh, i had hoped to never have to tell people to use [expr], but
> > there you go:
> >
> > [-1\
> > |
> > [pack 0 2]
> > |
> > [expr pow(\$f1, \$f2)]
> > |
> > [1\
> >
> > vbmdf
> > IOhannes
> > -----BEGIN PGP SIGNATURE-----
> > Version: GnuPG v1.4.12 (GNU/Linux)
> > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> >
> > iEYEARECAAYFAlF1LW8ACgkQkX2Xpv6ydvRWDgCffaIHH1qXGqFYLlt1iiJQFW5Q
> > OdEAnR8WVw+zxRKd8LWjVo95daJ/Aq6Y
> > =PbB6
> > -----END PGP SIGNATURE-----
> >
> > _______________________________________________
> > Pd-list at iem.at mailing list
> > UNSUBSCRIBE and account-management ->
> > http://lists.puredata.info/listinfo/pd-list
> >

> _______________________________________________
> Pd-list at iem.at mailing list
> UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list

```