# to the nth power

Erik Naggum enag at ifi.uio.no
Sun Nov 4 00:54:27 AEST 1990


In article <1990Nov2.182217.13958 at NCoast.ORG> catfood at NCoast.ORG (Mark W. Schumann) writes:

   Spiffy, but it does depend on (exponent & 1) being the same as saying
   "exponent is odd."  Most implementations support this, though.
   Again, neither solution supports negative exponents.

Which are the implementations that doesn't?

For all positive integers, you can prove that odd integers have the
least significant bit equal to one, and even integers have the least
significant bit equal to zero, when represented in binary.  Hint: odd,
positive integers have a remainder of 1 when divided by 2.

For a ones-complement architectures, this even holds for negative
integers.  Twos-complement architectures will return "odd" for an even
negative number in this simple test.  Was that what you were thinking
of?

--
[Erik Naggum]	Naggum Software
		Holmens gt 3, 2nd floor			<== NEW!
		BOX 1570 VIKA / 0118 OSLO / NORWAY	<== NEW!
--



More information about the Comp.lang.c mailing list