Author Topic: How to do power of calculations  (Read 366 times)

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: How to do power of calculations
« on: August 19, 2016, 09:38:14 am »
Thanks,

There seems to be something wrong with the Pow function. Here is my code:

Code: [Select]
    Public Function readAltitude(seaLevel As Float) As Float
       
        // Equation taken from BMP180 datasheet (page 16):
       
        // Note that using the equation from wikipedia can give bad results
        // at high altitude.
       
        Dim atmospheric As Float = readPressure()
        Dim factor As Float = atmospheric / seaLevel
        A_factor = factor.Pow(0.1903) // value used for debuging
        Return 44330.0 * (1.0 - (factor.Pow(0.1903)))
    End Function

This gives incorrect values. Checking, I find the factor is correct - for atmospheric at 1000.802795 and sealLevel at 1000.00 the factor is 1.000802795 (correct). If I then raise this to the power of 0.1903 (which is 1/5.255) I get 0.189175 which is not correct - this should be 1.00015 (aprox).

Any idea what is going on here?

Thanks.