Code: pow with negative base does #IND

If you require help or assistance with anything then please post here

Moderators: electrogear, exonerate

Code: pow with negative base does #IND

Postby jacob on Sat Jun 02, 2012 10:52 am

Code: Select all
x = pow(-1,4);


Why does this code show me -1.#IND on the streamout? Instead of correct value -> 1.
Last edited by jacob on Sat Jun 02, 2012 11:18 am, edited 1 time in total.
User avatar
jacob
essemer
 
Posts: 18
Joined: Thu May 31, 2012 8:14 am
Location: Germany

Re: Code: pow with negative base does #IND

Postby CoreStyler on Sat Jun 02, 2012 11:10 am

You will never get >4. At least you will get 4.
To do a statement is better to use green data, and streambool out the result (0 is false, 1 is true).
and -1 * -1 *-1 *-1 = 1.
http://www.thecorestylerz.net
Sound Design, synth development and websites building...
Image
SM COMMUNITY IS MOVING TO
www.synthmakers.net
User avatar
CoreStyler
essemilian
 
Posts: 474
Joined: Sun May 23, 2010 1:25 pm

Re: Code: pow with negative base does #IND

Postby jacob on Sat Jun 02, 2012 11:17 am

CoreStyler wrote:You will never get >4. At least you will get 4.
To do a statement is better to use green data, and streambool out the result (0 is false, 1 is true).


Sorry, that was wrong. I want 1 to come out and not the 4 I mentioned first.
Negative Power.osm
(17.05 KiB) Downloaded 35 times
User avatar
jacob
essemer
 
Posts: 18
Joined: Thu May 31, 2012 8:14 am
Location: Germany

Re: Code: pow with negative base does #IND

Postby CoreStyler on Sat Jun 02, 2012 11:31 am

jacob wrote:
CoreStyler wrote:You will never get >4. At least you will get 4.
To do a statement is better to use green data, and streambool out the result (0 is false, 1 is true).


Sorry, that was wrong. I want 1 to come out and not the 4 I mentioned first.
The attachment Negative Power.osm is no longer available


Done. you want to have a negative phase?
Negative Power.osm
(19.26 KiB) Downloaded 36 times


To calculate:
pow (-1,4) synthmaker not work (don't know why).
But doing
pow (1,4) * -1 does. ;)

And with your code you bypassed the input.
So i addedd
out = in + pow(1,4) * -1;
instead of
out = pow(1,4) * -1;
Because you bypass the input that does not affect anything.
http://www.thecorestylerz.net
Sound Design, synth development and websites building...
Image
SM COMMUNITY IS MOVING TO
www.synthmakers.net
User avatar
CoreStyler
essemilian
 
Posts: 474
Joined: Sun May 23, 2010 1:25 pm

Re: Code: pow with negative base does #IND

Postby jacob on Sat Jun 02, 2012 11:39 am

CoreStyler wrote:Done. you want to have a negative phase?
Negative Power.osm


To calculate:
pow (-1,4) synthmaker not work (don't know why).
But doing
pow (1,4) * -1 does. ;)

And with your code you bypassed the input.
So i addedd
out = in + pow(1,4) * -1;
instead of
out = pow(1,4) * -1;
Because you bypass the input that does not affect anything.


Thank you for your very fast answers and the osm. but this is not what I was after. I want 1 be negative or positive depending on the exponent. So every even number (2,4,6,...) makes it positive:
(-1)^4 = (-1)*(-1)*(-1)*(-1) = 1
And every uneven number (1,3,5,...) makes it negative:
(-1)^3 = (-1)*(-1)*(-1) = -1
User avatar
jacob
essemer
 
Posts: 18
Joined: Thu May 31, 2012 8:14 am
Location: Germany

Re: Code: pow with negative base does #IND

Postby jacob on Sat Jun 02, 2012 12:57 pm

I solved it with another calculation. Dividing the variable by 2 and checking if it has decimal places - by checking it against the rounded value. But it would be better if the pow() would work.
Negative Power.osm
(17.76 KiB) Downloaded 52 times
User avatar
jacob
essemer
 
Posts: 18
Joined: Thu May 31, 2012 8:14 am
Location: Germany

Re: Code: pow with negative base does #IND

Postby martinvicanek on Sat Jun 02, 2012 4:55 pm

SM's implementation of pow() allows for non-integer exponents hence it expects a positive base to make sure that the result is a real (not a complex) number.
martinvicanek
essemilian
 
Posts: 306
Joined: Sun Mar 13, 2011 1:15 pm

Re: Code: pow with negative base does #IND

Postby jacob on Sun Jun 03, 2012 8:24 am

martinvicanek wrote:SM's implementation of pow() allows for non-integer exponents hence it expects a positive base to make sure that the result is a real (not a complex) number.


Thank you for this info.
User avatar
jacob
essemer
 
Posts: 18
Joined: Thu May 31, 2012 8:14 am
Location: Germany


Return to Help

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron