Mirage Source
Add() - Printable Version

+- Mirage Source (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: Resources (https://mirage-engine.uk/forums/forumdisplay.php?fid=49)
+---- Thread: Add() (/showthread.php?tid=369)

Pages: 1 2


Add() - William - 16-10-2006

Hehe Tongue You wanted more tutorials Wink hehe.

Add:
Code:
Public Function Add(ByVal a As Long, ByVal b As Long)
Add = a + b
End Function

Usage:
Code:
Dim i As Long
i = Add(3, 5)

"i" would result in 8 Smile Aint I good ?


- Spodi - 16-10-2006

Congradulations, you managed to needless slow down and obfuscate the most simple form of math. :lol: :wink:

Though learning how to use functions appropriate is a pretty good thing. Just keep in mind that if you have:

Code:
Public Function MyFunc()

You need to define what type of format it is working in as MyFunc will be handled as a variable. In your example, you are making "Add" a variant (default variable format of a variable without a specified format).

Code:
Public Function MyFunc() As Long

Would make Add return a long.

Sorry, just wanted to point that out in case you didn't know. :wink:


- William - 16-10-2006

I never really added that to my mind.. that part has been so obvious so I kinda never learned it Tongue So thanks for reminding me.


- William - 16-10-2006

At least Add() looks professional Tongue hehe


- Leighland - 16-10-2006

Code:
Public Function Add(ByVal a As Long, ByVal b As Long)
        Add = a + b
End Function


Awww there ya go Verrigan... lol


- Misunderstood - 16-10-2006

Thats too big of an indent Tongue


- William - 16-10-2006

and you forgot as long after the function Tongue


- Leighland - 17-10-2006

Too long of an indent cuz I did it manually with the spacebar lmao.

Code:
Public Function Add(ByVal a As Long, ByVal b As Long) As Long
     Add = a + b
End Function
There...


- Obsidian - 17-10-2006

i HATE when people don't nest their code...

isn't it faster just to do

i = 5+3

instead of

i = Add(5,3)

it's less to type... but congrats for submitting something new :wink:


- William - 18-10-2006

Haha..Obsidian, the whole topic was a joke. And you were the only one who didnt get it Tongue


- Obsidian - 18-10-2006

oh no i figured it was... :roll:


- halla - 18-10-2006

We cant leave subtraction out of the mix.

Code:
Public Function Subtract(ByVal a As Long, ByVal b As Long) as Long
         Subtract = a - b
End Function

Code:
Public Function Multiply(ByVal a As Long, ByVal b As Long) as Long
         Multiply = a * b
End Function

Code:
Public Function Divide(ByVal a As Long, ByVal b As Long) as Long
         Divide = a / b
End Function

There now the basic math functions don't feel left out.


- pingu - 18-10-2006

I dare somebody to do square root without the "Sqrt()" functon...


- Misunderstood - 18-10-2006

Code:
Public Function SquareRoot(ByVal a As Double) as Double
         SquareRoot=a^(1/2)
End Function



- Leighland - 18-10-2006

Rofl, how about percentage? :p


- Spodi - 18-10-2006

http://en.wikipedia.org/wiki/Methods_of ... uare_roots


- Spodi - 18-10-2006

Code:
Public Sub TestOne(ByVal Index As Long)
Dim a As Single
    
    a = Sqr(LookupTable(Index))
    
End Sub

Code:
Public Sub TestTwo(ByVal Index As Long)
Dim a As Single
    
    a = LookupTable(Index) ^ 0.5
    
End Sub

Code:
%Faster   -98.4|   -98.4|   -98.4|   -98.4|   -98.4|   -98.4|   -98.5|   -98.4|   -98.4|   -98.4
Test1       162|     160|     169|     161|     160|     161|     159|     161|     160|     161
Test2     10272|   10262|   10263|   10283|   10281|   10274|   10278|   10267|   10258|   10265

Nope. Not by a long shot. :wink:


- halla - 19-10-2006

Leighland Wrote:Rofl, how about percentage? :p

What do you mean?


- Misunderstood - 19-10-2006

Right, raising to the .5 is generally much slower in most programing languages than the buit in sqrt function.


- Spodi - 19-10-2006

Compiled, 5000 loops per each result. :wink:


- William - 20-10-2006

Haha.. So my Add command developed itself into a massive math lesson. Well, one thing is good about these. They can easilt be used for sadscript Tongue


- William - 20-10-2006

Why, does functions run faster in VB.net?


- William - 20-10-2006

I think he means that its not good in VB. But in VB.net.. maybe I missunderstood it..


- Misunderstood - 20-10-2006

William Wrote:I think he means that its not good in VB. But in VB.net.. maybe I missunderstood it..

I think you misunderstood Tongue


- William - 20-10-2006

Yeah, guessed so. You ment that it doesn't support Math.Tan etc?