[Include] Simple Mathematics
#1


A math include for problem solving..
Why? What? Why'd you make this

I thought about it, and I was thinking is there any ways I could do equations more tidier? Well I here made this for myself thought since I don't always use it, I would share it among the community :P

You may seem to think it's useless but hey, works fine for me and does a superb job for me. Some functions return decimals (such as floats) and some return whole numbers. So make sure you check what you're doing!

There are 17 functions all related to numbers (or in other words, math). I managed to make a function relating to some mathematical theorems. Though the new 6 basic functions, plus, minus, times, divide, sqroot, power. They haven't been fully tested but if there is problems with it, please do report it here.

Functions
pawn Код:
/*
    native Math.Pi()   
    native Math.Infinite()
    native Math.Highest(...)
    native Math.Add(val, val2)
    native Math.Subtract(val, val2)
    native Math.Divide(val, val2)
    native Math.Multiply(val, val2)
    native Math.SquareRoot(Value)
    native Math.Power(val, val2)
    native Math.Mean(...)
    native Math.Pythagoras( Float: val1, Float: val2, bool: shortside = false )
    native Math.GetMiddlePos(Float: X, Float: Y, Float: X2, Float: Y2, &Float: vX, &Float: vY)
    native Math.RandomEx(min, max)
    native Math.RandomPlayer()
    native Math.IsPositive( num )
    native Math.IsNegative( num )
    native Math.Random3DCoord( Float: minx, Float: miny, Float: minz, Float: maxx, Float: maxy, Float: maxz, &Float: randx, &Float: randy, &Float: randz)
*/
By looking at the functions, they're easy to know what they are. Pretty much self explanatory.

Yes I know, they're also in functions. Please don't complain about me converting them to defines/macros.

Credits
Mauzen - Arithmetic mean value.
Lorenc - Most of the functions
RyDeR` - RandomEx calculation
[HiC]TheKiller - Minor fixes/help

Logs
Код:
** Released 
Fixed several things listed - <<
Note: I'm not the best at math though I can do some things. However, I would accept function suggestions if I know how they're operated/made.

Ask RyDeR` for mathematic problems lol, his a mathematician pro!

Download

Version 1.1

Problems/Suggestions?
Please do bump the thread with suggestions, would be more than welcome to add them

Problems? Please post here so I can fix them as soon as possible.

I will update the thread for new functions and bug fixes, so stay tuned.
Reply
#2

nice, very nice!

downloading ...
Reply
#3

Good Job!
Reply
#4

there's quite a few pointless ones, like Math.Add
also there's functions that won't work like

pawn Код:
stock Math.RandomPlayer( ) // Correct
{
        new
                pCount,
                val
        ;
        for(new i, g = GetMaxPlayers(); i < g; i++)
        {
                if(IsPlayerConnected(i)) pCount++;
        }
        val = random(pCount);
        return val;
}
it could return a non connected player

also this will return -.99 to -.01 as a positive
pawn Код:
stock bool: Math.IsPositive( Float: num ) // Correct
{
        if( num > -1 ) return true;
        return false;
}
and Math.Highest(...) won't work if you use all negative numbers
and you use RandomEx in the script but it should be Math.RandomEx

that's all just by looking over it
Reply
#5

Quote:
Originally Posted by cessil
Посмотреть сообщение
there's quite a few pointless ones, like Math.Add
also there's functions that won't work like

pawn Код:
stock Math.RandomPlayer( ) // Correct
{
        new
                pCount,
                val
        ;
        for(new i, g = GetMaxPlayers(); i < g; i++)
        {
                if(IsPlayerConnected(i)) pCount++;
        }
        val = random(pCount);
        return val;
}
it could return a non connected player

also this will return -.99 to -.01 as a positive
pawn Код:
stock bool: Math.IsPositive( Float: num ) // Correct
{
        if( num > -1 ) return true;
        return false;
}
and Math.Highest(...) won't work if you use all negative numbers
and you use RandomEx in the script but it should be Math.RandomEx

that's all just by looking over it
Thanks for that, I completely forgot while I was writing this function however they should be fixed. I'm currently at my cousins house and he doesn't have SA-MP nor the compiler and dial-up lawl. I've fixed it in notepad but not 100% correct if it'll work.

Updated :P
Reply
#6

Hope this might help you: http://i.imgur.com/HCDtq.jpg to add some more functions. I just wrote it to explain someone, it has some formulas that might help you, like distance between two points in 3D, internal division, external division
Reply
#7

Nice include, good job mate.
Reply
#8

very cool, good job
Maybe more cleaner script, ex. you do
pawn Код:
new
val
;
It could be
pawn Код:
new val;
Reply
#9

Quote:
Originally Posted by System64
Посмотреть сообщение
very cool, good job
Maybe more cleaner script, ex. you do
pawn Код:
new
val
;
It could be
pawn Код:
new val;
*facepalm*
Nice idea Lorenc ^.^
Reply
#10

I don't get the point of all those basic arithmetic functions. How this
pawn Код:
new var = Math.Add(1, 2);
better than this?
pawn Код:
new var = 1 + 2;
Congratulations, you've just invented a bicycle...

Also, this is a better way to do things:
pawn Код:
stock Math.Add( val, val2 ) return val+val2; //That's it. The whole function. But the most pointless one...
Reply
#11

Looks cool, especially Pythagora's)
Reply
#12

Nice work!

Maybe some other angle functions too in next version?
Reply
#13

Code:
stock Float: Math.Pie( ) return ( 3.14159265 ); // Correct!
stock Math.Infinite( ) return ( 0x7F800000 ); // Correct!
stock Math.SquareRoot( Float: Val ) return floatsqroot(Val); //Correct but nothing useful... lol.
Or just...
Code:
#define Math.Pie() (3.14159265)
#define Math.Infinite() (0x7F800000)
#define Math.SquareRoot(%0) (floatsqroot(%0))
Also, why do we need stuff like this:
Code:
Math.Power
Math.Multiply
Math.Divide
Math.Substract
Math.Add
You've got these functions in the float.inc as well, which are most probably even faster?
Code:
floatpower
floatmul
floatdiv
floatsub
floatadd
I also didn't know that 0 was a positive number 0.o

Edit: This actually is real simple math
Reply
#14

Code:
stock bool: Math.IsPositive( Float: num ) // Correct
{
        if( num >= 0 ) return true;
        return false;
}
Definitely NOT correct. Since when is 0 positive?

Also, you forgot Lowest, since there is Highest.

And if i remember correctly char arrays([MAX_PLAYERS char]) store integers from -125 to 125.
So you can't use it in RandomPlayer.
Reply
#15

Okay, tommrow since I'm not at home yet. I'll be fixing up these and converting them to macros. Of course, yes, this is meant to be a 'simple math' include. I added those 4 functions for the sake of it. But i'll remove them since I'm creating 4 32 bit variables D:
Reply
#16

Lorenc_ your super duper matematic! : D

Nice.
Reply
#17

Code:
stock minrand(min, max) //By Alex "Y_Less" Cole
{
	return random(max-min)+min;
}

And I think Iter_Random(Player) is faster.
Reply
#18

That Math.Pie must be tasty!
Reply
#19

Quote:
Originally Posted by Double-O-Seven
View Post
That Math.Pie must be tasty!
Yes, indeed I was rotating a wheel object and it did actually stop at "math.pie()". Deleted the code before, I'll try to make it soon.

:P

@varthshenon

I'd supposedly say so. Foreach is fast into looping as well. However I'm rewriting the functions in defines later. Not sure if 'defines' make a speed difference but they do shorten the code.

@Raimis_R

Haha, wish I was better though and knew alot more formulas! But to admit it. I'm not the best/good at it, though I can do some jobs in it.

Pythagoras should be a useful function :P
Reply
#20

Quote:
Originally Posted by Lorenc_
View Post
Yes, indeed I was rotating a wheel object and it did actually stop at "math.pie()". Deleted the code before, I'll try to make it soon.

:P

@varthshenon

I'd supposedly say so. Foreach is fast into looping as well. However I'm rewriting the functions in defines later. Not sure if 'defines' make a speed difference but they do shorten the code.

@Raimis_R

Haha, wish I was better though and knew alot more formulas! But to admit it. I'm not the best/good at it, though I can do some jobs in it.

Pythagoras should be a useful function :P
I just wanted to say the Math.Pie isn't correct. It's Math.Pi.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)