Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

how to format math functions (ie, '^') in delphi ?

mydelphimydelphi Member Posts: 62
Hello.

I'm having the hardest of time, trying to find the math
equivalent (reference) to proper delphi syntax use.

For example, if I want to calculate:

-----------------------------
uses MATH;

.
.

Y := floor(2^(M-8))

.
.

-----------------------------

Delphi won't compile this code, and then gives me an error message
relating to Pointers.

I can't fine anything on the equivalent to using 'power of' or
whatever its called ( '^' chars ) in my delphi calculations.

I know that there are other format or syntax issues with certain
charators, but I dont' know them all. That is why I was searching
for a reference guide or something.

I know about the MATH unit and Delphi Help reference, listing all
the math functions, like Sqrt(x), etc etc.

Thank you for any help on this matter.
-mydelphi

Comments

  • zibadianzibadian Member Posts: 6,349
    : Hello.
    :
    : I'm having the hardest of time, trying to find the math
    : equivalent (reference) to proper delphi syntax use.
    :
    : For example, if I want to calculate:
    :
    : -----------------------------
    : uses MATH;
    :
    : .
    : .
    :
    : Y := floor(2^(M-8))
    :
    : .
    : .
    :
    : -----------------------------
    :
    : Delphi won't compile this code, and then gives me an error message
    : relating to Pointers.
    :
    : I can't fine anything on the equivalent to using 'power of' or
    : whatever its called ( '^' chars ) in my delphi calculations.
    :
    : I know that there are other format or syntax issues with certain
    : charators, but I dont' know them all. That is why I was searching
    : for a reference guide or something.
    :
    : I know about the MATH unit and Delphi Help reference, listing all
    : the math functions, like Sqrt(x), etc etc.
    :
    : Thank you for any help on this matter.
    : -mydelphi
    :
    The Power() and IntPower() functions can be used to calculate powers.
    Here are some chars which have special meanings:
    ^: pointer dereferencing
    []: Array index
    {}: Comment
    @: Pointer reference (See Address)
    #: ascii code

  • rezashahranrezashahran Member Posts: 21
    : : Hello.
    : :
    : : I'm having the hardest of time, trying to find the math
    : : equivalent (reference) to proper delphi syntax use.
    : :
    : : For example, if I want to calculate:
    : :
    : : -----------------------------
    : : uses MATH;
    : :
    : : .
    : : .
    : :
    : : Y := floor(2^(M-8))
    : :
    : : .
    : : .
    : :
    : : -----------------------------
    : :
    : : Delphi won't compile this code, and then gives me an error message
    : : relating to Pointers.
    : :
    : : I can't fine anything on the equivalent to using 'power of' or
    : : whatever its called ( '^' chars ) in my delphi calculations.
    : :
    : : I know that there are other format or syntax issues with certain
    : : charators, but I dont' know them all. That is why I was searching
    : : for a reference guide or something.
    : :
    : : I know about the MATH unit and Delphi Help reference, listing all
    : : the math functions, like Sqrt(x), etc etc.
    : :
    : : Thank you for any help on this matter.
    : : -mydelphi
    : :
    : The Power() and IntPower() functions can be used to calculate powers.
    : Here are some chars which have special meanings:
    : ^: pointer dereferencing
    : []: Array index
    : {}: Comment
    : @: Pointer reference (See Address)
    : #: ascii code
    :
    :
    This is the Function of Power :
    ---------------------------------------------------------
    function Power(const Base, Exponent: Extended): Extended;
    begin
    if Exponent = 0.0 then
    Result := 1.0 { n**0 = 1 }
    else if (Base = 0.0) and (Exponent > 0.0) then
    Result := 0.0 { 0**n = 0, n > 0 }
    else if (Frac(Exponent) = 0.0) and (Abs(Exponent) <= MaxInt) then
    Result := IntPower(Base, Integer(Trunc(Exponent)))
    else
    Result := Exp(Exponent * Ln(Base))
    end;
    Reza

Sign In or Register to comment.