I have moved my blog to Wordpress at theunixgeek.wordpress.com. I will still be checking back periodically on this one as well, though. 19 April 2009

featured

Merging Mkdir and Cd | 280 Slides Interview | I Switched to KDE 4

clickable portals

Sunday, November 11, 2007

A Simple Cocoa Algorithm for Exponents

Here's a quick little Cocoa implementation algorithm for when you need to find powers of numbers. I'm assuming you have instances of NSTextField called FirstVariable, toThePowerOf, and result.

- (IBAction)findPower:(id)sender{
float exponent;
exponent = [toThePowerOf floatValue];

float power; //number to be raised to power
power = [firstVariable floatValue];
while (exponent > 1){
power = power * power;
exponent = exponent - 1;
}
[result setFloatValue:power];
[result setNeedsDisplay:YES];
}

1 comments:

pbsl said...

you have a nice site. thanks for sharing this site. you can download lots of ebook from here

http://feboook.blogspot.com