Results 1 to 3 of 3

Thread: [RESOLVED] pow : why it error

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2017
    Posts
    163

    Resolved [RESOLVED] pow : why it error

    Private Sub Form_Load()

    Debug.Print (-0.1) ^ 0.3 ' vb show error

    End Sub
    Last edited by quickbbbb; Sep 14th, 2021 at 07:10 AM.

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    4,707

    Re: pow : why it error

    From the help:
    Syntax

    result = number^exponent

    The ^ operator syntax has these parts:
    Code:
    PartDescription 
    result     Required; any numeric variable. 
    number     Required; any numeric expression. 
    exponent   Required; any numeric expression.
    Remarks

    A number can be negative only if exponent is an integer value. When more than one exponentiation is performed in a single expression, the ^ operator is evaluated as it is encountered from left to right.
    This doesn't work either
    Code:
    Private Sub Form_Load()
      Dim a As Double, p As Double
    
      ' Fails:
      Debug.Print CDbl(-0.1) ^ CDbl(0.3)
      
      ' Fails:
      a = -0.1: p = 0.3
      Debug.Print a ^ p
      
      ' Fails:
      Debug.Print Math_Pow(-0.1, 0.3) ' vb show error
    
    End Sub
    
    Private Function Math_Pow(ByVal a As Single, ByVal p As Single) As Double
      Math_Pow = a ^ p
    End Function

  3. #3
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    4,707

    Re: [RESOLVED] pow : why it error

    Some reading about this topic of calculating powers of negative numbers when p<1
    https://stackoverflow.com/questions/...e-float-number

    Imaginary numbers -> Square Roots
    https://en.wikipedia.org/wiki/Imagin...t#Square_roots

    https://www.algebra.com/algebra/home...-number.lesson
    Last edited by Arnoutdv; Sep 14th, 2021 at 08:00 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width