0
\$\begingroup\$

I am attempting to create a calculator using Keil C51 compiling for a DS89c450 target device, but I have run into an obstacle with regards to negative powers. The compiler keeps returning errors when ever I attempt to calculate the inverse of a trigonometric function and a run time error (a null response) occurs when I try negative powers. I believe the documentation states this isn't possible, is it possible with the default math.h or, if not, how would I go about achieving this?

To clarify, this is being completed in C, to assembly.

Thanks for any assistance.

\$\endgroup\$
6
  • \$\begingroup\$ You're using the floating point version of the function? \$\endgroup\$ Jul 5, 2015 at 4:20
  • \$\begingroup\$ @IgnacioVazquez-Abrams I have only tried using int/long inputs, although I have been storing the potential output (excepting the error) in a float. If you refer to a seperate function, that is, other than pow(number, power), then no, I haven't but would love to know of it. \$\endgroup\$ Jul 5, 2015 at 4:23
  • \$\begingroup\$ It might have been a few years, but surely you have been shown a way to express this value with a positive exponent... \$\endgroup\$ Jul 5, 2015 at 4:31
  • \$\begingroup\$ non-integer powers of a negative number are supposed to give you a domain error, but that would be a run-time error not a 'compiler error'. Please supply the smallest code fragment and exact error message that illustrates the problem. \$\endgroup\$ Jul 5, 2015 at 4:34
  • \$\begingroup\$ @ChrisStratton Now that you mention it, yes, that would be entirely viable. Just didn't even think of it. More the worry is it isn't even history, I haven't even finished school yet! \$\endgroup\$ Jul 5, 2015 at 4:35

1 Answer 1

1
\$\begingroup\$

Negative powers are equal to the inverse of the original to the power of the absolute original value. That is to say:

x^-y = 1/x^y

With regards to inverse trigonometric functions, the inverse of a function is also known as the arc of it. eg; sin^-1 = asin cos^-1 = acos tan^-1 = atan

Thanks to Chris Stratton for that helpful reminder!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.