Squaring negative numbers gives nan

Squaring negative numbers gives nan

Postby Billk » Sat Dec 07, 2013 10:03 am

-n^2 or (-2)^3 causes nan error
Posts: 1
Joined: Sat Dec 07, 2013 9:58 am

Re: Squaring negative numbers gives nan

Postby joe » Sun Dec 08, 2013 11:00 am

Previously, the power function would do the appropriate conversion to complex numbers for this case. However, this caused lots of problems for people doing more standard calculations.

I solved this by creating two forms of the power functions, one for real numbers, one for complex numbers. In order to get the powers of negative numbers it is necessary to convert your values to Complex numbers using the Complex constructor in the 'obj' tab.

There should be another way to convert your numbers to complex which is just to add 0*i to it, but testing right now I seem to have broken something in the calculation and the conversion is not occurring. So, I need to track down that bug and fix it.

Further, I realize that in this case both the input and output is real and so needing to convert it to Complex may seem a bit awkward. I believe the NaN is being thrown by the base math library and would be considered the correct answer in this case. But, I will do some double checking to make sure on this point.

Thanks a lot for the feedback.
User avatar
Site Admin
Posts: 241
Joined: Thu Jul 16, 2009 3:19 am

Return to Oovium

Who is online

Users browsing this forum: No registered users and 1 guest