Raised This Month: $12 Target: $400
 3% 

Log() and exp() of c++ to pawn


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
FeehSK
Junior Member
Join Date: Jul 2019
Location: MT - BRAZIL.
Old 02-15-2023 , 18:20   Log() and exp() of c++ to pawn
Reply With Quote #1

Hi, guys!
Can anyone tell me how I can use log() and exp() from c++ in pawn language?

But I don't turn around floatlog.
FeehSK is offline
Send a message via Skype™ to FeehSK
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-15-2023 , 18:42   Re: Log() and exp() of c++ to pawn
Reply With Quote #2

floatlog() and power() are the two equivalent functions.

If you are having issues using these functions, you should provide examples of how you're trying to use them.

Quote:
Originally Posted by FeehSK View Post
Hi, guys!
But I don't turn around floatlog.
I have no idea what that means.
__________________

Last edited by fysiks; 02-15-2023 at 18:43.
fysiks is offline
FeehSK
Junior Member
Join Date: Jul 2019
Location: MT - BRAZIL.
Old 02-15-2023 , 18:59   Re: Log() and exp() of c++ to pawn
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
floatlog() and power() are the two equivalent functions.

If you are having issues using these functions, you should provide examples of how you're trying to use them.



I have no idea what that means.
I'll show you a little bit of what it's all about.

function:

PHP Code:
public Update(idid2Float:Game)
{
    
// Compute the e and g function values
    
new Float:G(p[id2])
    new 
Float:E(gu[id], u[id2])

    
// Compute 1/v and v
    
new Float:invV * (1.0 e)
    new 
Float:1.0 invV

    
// Compute the delta value from the g, e, and v
    // values
    
new Float:dInner * (Game e)
    new 
Float:dInner

    
// Compute new rating, deviation and volatility values
    
new FloatsPrime floatexp(Convergence(dvp[id], s[id]) / 2.0)
                        
//exp(Convergence(d, v, p, s)/2.0)
       
new FloatpPrime 1.0 xs_sqrt((1.0 / (p[id] * p[id] + sPrime sPrime)) + invV)
    new 
FloatuPrime u[id] + pPrime pPrime dInner

    u
[id] = uPrime
    p
[id] = pPrime
    s
[id] = sPrime

Will call for:

PHP Code:
/// Computes the value of the g function for a rating
stock Float:G(Float:deviation)
{
    new 
Float:scale deviation M_PI

    
return 1.0 xs_sqrt(1.0 3.0 scale scale)
}

        
/// Computes the value of the e function in terms of a g function value
        /// and another rating
stock Float:E(Float:gFloat:RatingPlayerFloat:RatingPlayer2)
{
     new 
Float:exponent = -1.0 * (RatingPlayer RatingPlayer2)

     return 
1.0 / (1.0 floatexp(exponent))
}

stock Float:Convergence(const Float:d,
                           const 
Float:v,
                           const 
Float:p,
                           const 
Float:s)
{
    
// Initialize function values ​​for the iteration procedure
    
new Float:dS d
    
new Float:pS p
    
new Float:tS kSystemConst kSystemConst
    
new Float:log)

    
// Select upper and lower iteration ranges
    
new Float:a
    
new Float:B
    
new Float:bTest dS pS v

    
if (bTest 0.0)
    {
        
log(bTest)
    }
    else
    {
        
kConvergence
        
while (F(BdSpSvatS) < 0.0)
        {
            
-= kConvergence
        
}
    }

    
// run the iteration
    
new Float:fA F(AdSpSvatS)
    new 
Float:fB F(BdSpSvatS)
    while (
floatabs(A) > kConvergence)
    {
        new 
Float:+ (B) * fA / (fB fA)
        new 
Float:fC F(CdSpSvatS)

        if (
fC fB 0.0)
        {
            
B;
            
fA fB;
        }
        else
        {
            
fA /= 2.0;
        }

        
C;
        
fB fC;
    }

    return 
A;

But when it calculates, it gives this error:

[AMXX] Run time error 26: domain error
[AMXX] [0] rating.sma:: Convergence (line 643)
[AMXX] [1] rating.sma:: Update (line 587)
[AMXX] [2] rating.sma:: DeathMsg (line 310)
FeehSK is offline
Send a message via Skype™ to FeehSK
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-16-2023 , 00:11   Re: Log() and exp() of c++ to pawn
Reply With Quote #4

When posting an error that references a snippet of code, you need to show us which line is referenced by the error (because we can't use the line numbers due to not having the full code).

Also, you're using log() instead of floatlog(). I couldn't find any references to a function called log().
__________________
fysiks is offline
FeehSK
Junior Member
Join Date: Jul 2019
Location: MT - BRAZIL.
Old 02-16-2023 , 22:53   Re: Log() and exp() of c++ to pawn
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
When posting an error that references a snippet of code, you need to show us which line is referenced by the error (because we can't use the line numbers due to not having the full code).

Also, you're using log() instead of floatlog(). I couldn't find any references to a function called log().
log() is referring to -> log(%0) floatlog( %0, 2.7182818 ) from the post: https://forums.alliedmods.net/showthread.php?t=301521.

part of the code

PHP Code:
public DeathMsg()
{
    new 
Killer read_data(1)
    new 
Victim read_data(2)

    if(
get_bool_casual())
    {
            
GetParam(KillerSkill[Killer][Rank], Skill[Killer][Dvt], Skill[Killer][Vlt])
            
GetParam(VictimSkill[Victim][Rank], Skill[Victim][Dvt], Skill[Victim][Vlt])

            
Update(KillerVictim1.0)
            
Update(VictimKiller0.0)

            
set_task(1.5"Apply"Killer)
            
set_task(2.5"Apply"Victim)
        }
    }
}

public 
GetParam(id, const Float:rating, const Float:deviation, const Float:volatility)
{
    
u[id] = (rating kDefaultR) / kScale
    p
[id] = deviation kScale
    s
[id] = volatility
}

public 
Update(idid2Float:Game)
{
    
// Calcular os valores das funções E e G
    
new Float:G(p[id2])
    new 
Float:E(gu[id], u[id2])

    
// Calcular 1 /v e v
    
new Float:invV * (1.0 e)
    new 
Float:1.0 invV

    
// Calcule o valor delta de g, e e v
    // valores
    
new Float:dInner * (Game e)
    new 
Float:dInner

    
// Calcule novos valores de classificação, desvio e volatilidade
    
s[id] = floatexp(Convergence(dvp[id], s[id]) / 2.0)
                        
//exp(Convergence(d, v, p, s)/2.0)
    
p[id] = 1.0 xs_sqrt((1.0 / (p[id] * p[id] + s[id] * s[id])) + invV)
    
u[id] = u[id] + p[id] * p[id] * dInner
}

public 
Apply(id)
{
    
Skill[id][Rank] = ((u[id] * kScale) + kDefaultR)
    
Skill[id][Elo] = ((u[id] * kScale) + kDefaultR)
    
Skill[id][Dvt] = p[id] * kScale
    Skill
[id][Vlt] = s[id] * kDefaultS

    u
[id] = 0.0
    p
[id] = 0.0

    s
[id] = log(Skill[id][Vlt] * Skill[id][Vlt]) // Error calculating logarithm
}

/// Computes the value of the g function for a rating
stock Float:G(Float:deviation)
{
    new 
Float:scale deviation M_PI

    
return 1.0 xs_sqrt(1.0 3.0 scale scale)
}

        
/// Computes the value of the e function in terms of a g function value
        /// and another rating
stock Float:E(Float:gFloat:RatingPlayerFloat:RatingPlayer2)
{
     new 
Float:exponent = -1.0 * (RatingPlayer RatingPlayer2)

     return 
1.0 / (1.0 floatexp(exponent))
}

stock Float:Convergence(const Float:d,
                           const 
Float:v,
                           const 
Float:p,
                           const 
Float:s)
{
    
// Initialize function values ​​for the iteration procedure
    
new Float:dS d
    
new Float:pS p
    
new Float:tS kSystemConst kSystemConst
    
new Float:log// Error calculating logarithm. Value s = 0.06

    // Select upper and lower iteration ranges
    
new Float:a
    
new Float:B
    
new Float:bTest dS pS v

    
if (bTest 0.0)
    {
        
log(bTest)
    }
    else
    {
        
kConvergence
        
while (F(BdSpSvatS) < 0.0)
        {
            
-= kConvergence
        
}
    }

    
// run the iteration
    
new Float:fA F(AdSpSvatS)
    new 
Float:fB F(BdSpSvatS)
    while (
floatabs(A) > kConvergence)
    {
        new 
Float:+ (B) * fA / (fB fA)
        new 
Float:fC F(CdSpSvatS)

        if (
fC fB 0.0)
        {
            
B;
            
fA fB;
        }
        else
        {
            
fA /= 2.0;
        }

        
C;
        
fB fC;
    }

    return 
A;
}

stock Float:F(const Float:x,
                               const 
Float:dS,
                               const 
Float:pS,
                               const 
Float:v,
                               const 
Float:a,
                               const 
Float:tS)
{
    new 
Float:eX floatexp(x)
    new 
Float:num eX * (dS pS eX)
    new 
Float:den pS eX

    
return (num / (2.0 den den)) - ((a) / tS)

Lines that are in trouble
PHP Code:
new Float:log)
//and
s[id] = floatlog(Skill[id][Vlt] * Skill[id][Vlt]) 
I've tried with floatlog and the same problem.
FeehSK is offline
Send a message via Skype™ to FeehSK
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:52.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode