Home Page

Tips page
c
cellulari
debian
egittologia
emacs
emacs-latex
hardware
html
inglese
java
latex
linux
matlab
misc
mysql
network
octave
programming

*Raise A to the power of B
*Usare il profiler
*Variabili d'ambiente per gcc

python
security
sed
tech
webapps
windows

University Page

Programming

Debian & Linux

Some works

About me

Del.icio.us Bookmarks

BOINC Combined Statistics

Site Statistics

Contact me sending an e-mail (antispam defense activated)

debian

hacker emblem

blogger

GeoURL

View Sandro Tosi's profile on LinkedIn

This is my Google PageRank

Title: Raise A to the power of B
Author: Sandro Tosi
Last modified: 2005-04-03

The easiest way to obtain A raised to the power of B, A^B from now, is
this:

  exp ( B * ln ( A ) )

let us explain why:

1.  exp ( X ) means  e^X, e is the  Euler number, base  of the natural
    logarithm, ln.

2.  ln ( X ) is the number Y such that e^Y = X; 

3.  ln ( X^Y ) = Y * ln ( X )

4.  e^ln( X ) = X

5.  exp ( B * ln ( A ) ) = e^( B * ln ( A ) ) = e^( ln ( A^B ) ) = A^B


If this math is not clear, go and read your high school math books!

Every  programming language  has these  mathematical  functions, maybe
with  a  different name  from  the  ones  above. Usually  they  return
floating  point  numbers,  with  no integer  equivalence  (it's  often
useless); but  with A and  B integer, A^B  will be an integer  too. In
this situation,  use the function ``floor''  (or something equivalent)
that returns the integer part of a float number.