Be a Supporter!

AS: Math - Intermediate

  • 3,170 Views
  • 19 Replies
New Topic Respond to this Topic
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
AS: Math - Intermediate Jul. 3rd, 2005 @ 03:17 PM Reply

AS: Main
Basic Math
The Math class in Flash consists of a very large set of operators, for calculating values while running the .swf

I'm going to go over some of the more advanced operators here, bitwise operations.

Basic Boolean Arithmatic Operators

Shift Operations
All numbers on your computer are represented as 0's and 1's more on the actual representation in math advanced. for now we need to know of 2 very quick

and very useful operators << and >> , they are "shift left" and "shift right" , we will use them for ultra fast multiplication and devision by

two, they are over 10 times faster then *2 and /2.

<< (bitwise left shift) is used to shift the bits left, for example
2 which is 10
will become 8 which is 1000
when shifted 2 to the left meaning 8 == 2 << 2;

5 which is 101
will become 10 which is 1010
when shifted 1 to the left, since 10==5 << 1;

all you need to really remmember, that you state the number of times you are multiplying by 2

the usage is as following object1 << object2 shifts object1 object2 locations.
if you want to shorten it and assign object1 = object1 << object2 you may use
object1 <<= object2, this will auto asign it to object 1

>> (bitwise shift right) is used for devision I will not bother explaining it since it does THE EXACT OPPISITE OF OBJECT 1.

remmember, this trick does not work on fractions

Strict Equality

you probebly know that 0 == false in flash, and that null is also the same, and true is equal to one and is equal to many other things, sometimes, knowing it is

equal is not enough, we also want to know it is the same type, for that the "===" operator exists, it checks if the object has the same value and is

the same type

false==0 returns true;
false===0 returns false;

pretty simple, yet very useful

Decreasment and Increasment by 1

to decrease a number called "num" by one all you really have to do is write

num--;

to increase it, you write

num++;

this is pretty handy in for loops, you use it alot in them. now there is an often overlooked difference between num++ and ++num, num++ triggers AFTER the

statement where ++num triggers while it, so for example if num is 7 i=num++ will make i 7 too but i=++num will make i8, num becomes 8 in both cases.

That's all for this time, actual boolean math in Math: Advanced.

Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS: Math - Intermediate Oct. 26th, 2005 @ 01:45 PM Reply

Lol, no replies, that's just sad :(
I think people are getting fed up from your 1337 AS:___ :P

As usual, nice tutorial...


BBS Signature
Creepy
Creepy
  • Member since: Nov. 28, 2004
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Math - Intermediate Oct. 26th, 2005 @ 01:47 PM Reply

At 10/26/05 01:45 PM, -Toast- wrote: Lol, no replies, that's just sad :(
I think people are getting fed up from your 1337 AS:___ :P

As usual, nice tutorial...

it took u 3 and a half month to say that? =)

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS: Math - Intermediate Oct. 26th, 2005 @ 01:48 PM Reply

Yeah toast get withthe times baby :P

Though when I saw only 1 reply I thought it was a remake or something


- Matt, Rustyarcade.com

Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS: Math - Intermediate Oct. 26th, 2005 @ 01:51 PM Reply

At 10/26/05 01:48 PM, Ninja-Chicken wrote:
Though when I saw only 1 reply I thought it was a remake or something

Nope, it's just that unpopular Inglor again, no one likes him - no one posts here :D


BBS Signature
liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS: Math - Intermediate Oct. 26th, 2005 @ 02:02 PM Reply

I haven't ever read this before, but I just did and I got the << and >> thing.. I want to learn more bitwise mathematics, I really don't understand it.. heh :)

Great tutorial, though there were a lot of linebreaks.. whats up there?


Sup, bitches :)

BBS Signature
Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS: Math - Intermediate Oct. 26th, 2005 @ 02:21 PM Reply

At 10/26/05 01:51 PM, -Toast- wrote:
At 10/26/05 01:48 PM, Ninja-Chicken wrote:
Though when I saw only 1 reply I thought it was a remake or something
Nope, it's just that unpopular Inglor again, no one likes him - no one posts here :D

No its just he writes so many that its hard to reply to all (especially the less useful ones)

The thing I find about inglors tutorials are that they assume you have a certain ammount of knowlage on the subject already and he wants to clarify it which unfortunatly isnt always the case.
Deltas tutorials are almost too in-depth which means its hard to get you're head around but when you do your an expert on the subject


- Matt, Rustyarcade.com

Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to AS: Math - Intermediate Oct. 26th, 2005 @ 02:50 PM Reply

At 10/26/05 02:02 PM, -liam- wrote: I haven't ever read this before, but I just did and I got the << and >> thing.. I want to learn more bitwise mathematics, I really don't understand it.. heh :)

Great tutorial, though there were a lot of linebreaks.. whats up there?

I never really knew what the << and >> did, but i know how to write binary numbers.

we'll take 4 0's for example, 0000

1000 is 8, 0100 is 4, 0010 is 2, 0001 is 1 (you dont need the 0's before the one)

So it's like a base 2 number system versus our base 10 number system.

1001010101 is 512+64+16+4+1 is 597

NegativeONE
NegativeONE
  • Member since: Feb. 15, 2003
  • Offline.
Forum Stats
Moderator
Level 49
Game Developer
Response to AS: Math - Intermediate Oct. 26th, 2005 @ 02:55 PM Reply

At 10/26/05 01:45 PM, -Toast- wrote: Lol, no replies, that's just sad :(
I think people are getting fed up from your 1337 AS:___ :P

I hardly think it's sad. Not to offend, but these just aren't among the most practical and essential pieces of script, except for increment and decrement, but I think everyone knows those - even Toast). You'd be hard pressed to find a person who was scouting around for a more efficient way to multiply by two. I'm by no means saying that they're useless, but there are a lot fewer ways that they'd be applied around here than - say - a jump script or something.


BBS Signature
Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS: Math - Intermediate Oct. 26th, 2005 @ 03:04 PM Reply

Yeah I learned alot about binary in my electronics class. It goes up in powers of 2.

Lets say you got

1001
8421

so 1001 = 9

Number << X

is moving the binary X ammount in the specified direction (so multiplying by that power of 2)

So

9 = 1001
9 << 2 = 100100

1 0 0 1 0 0
32 16 8 4 2 1

So

100100 = 36

9 << 2 = 36

Which if you work it out

9 X 2 = 18
18 X 2 = 36

)

Just thought id clear that up for the people who didnt knwo

4 << 6 == 4 x 2 x 2 x 2 x 2 x 2 x 2 == 256 == 100000000

)

- Matt, Rustyarcade.com

Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS: Math - Intermediate Oct. 26th, 2005 @ 03:12 PM Reply

At 10/26/05 02:55 PM, NegativeONE wrote:
I hardly think it's sad.

Well, no, but it's funny then no one actually noticed this thread.

Not to offend, but these just aren't among the most practical and essential pieces of script,

I agree, although everything in life can be useful :D

except for increment and decrement, but I think everyone knows those - even Toast).

Why are you implying the word "even", does it mean "even toast(Who is bad at maths)"? :P

You'd be hard pressed to find a person who was scouting around for a more efficient way to multiply by two.

That's true, I don't think I would have ever done that, heh.

I'm by no means saying that they're useless, but there are a lot fewer ways that they'd be applied around here than - say - a jump script or something.

Agreed.


BBS Signature
Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS: Math - Intermediate Oct. 26th, 2005 @ 03:13 PM Reply

Heh I think I just wasted 5 minuits :P


- Matt, Rustyarcade.com

NegativeONE
NegativeONE
  • Member since: Feb. 15, 2003
  • Offline.
Forum Stats
Moderator
Level 49
Game Developer
Response to AS: Math - Intermediate Oct. 26th, 2005 @ 03:41 PM Reply

At 10/26/05 03:12 PM, -Toast- wrote: I agree, although everything in life can be useful :D

Go read the General board for a day and reconsider that, heh.

Why are you implying the word "even", does it mean "even toast(Who is bad at maths)"? :P

B)


BBS Signature
liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS: Math - Intermediate Oct. 26th, 2005 @ 03:44 PM Reply

At 10/26/05 03:41 PM, NegativeONE wrote: Go read the General board for a day and reconsider that, heh.

The general board.. where being banned for spamming is rather random, you never know if a topic is going to be considered spam or not and you are unsure whether your post is contributing to the topic at hand or not. Mainly because you are unsure at what the topic at hand actually IS.


Sup, bitches :)

BBS Signature
Indian-Wrestler
Indian-Wrestler
  • Member since: Mar. 26, 2005
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to AS: Math - Intermediate Oct. 26th, 2005 @ 03:50 PM Reply

Nice tutorial,
this is helpful for things non-NG realated,like a school project

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS: Math - Intermediate Oct. 26th, 2005 @ 04:50 PM Reply

Nobody listens to me :P


- Matt, Rustyarcade.com

mb3
mb3
  • Member since: May. 20, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS: Math - Intermediate Dec. 18th, 2005 @ 03:49 PM Reply

this is how you could explain the shift thingy:
x << y = x * (y * 2)
x >> y = x / (y * 2)
i think that would be alot more easy.


|

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS: Math - Intermediate Dec. 18th, 2005 @ 03:54 PM Reply

At 12/18/05 03:49 PM, mb3 wrote: this is how you could explain the shift thingy:
x << y = x * (y * 2)
x >> y = x / (y * 2)
i think that would be alot more easy.

good makes it clearer but a n00by will look at that and cry

My post explains it in a way even a 5 year old could understand

(toaststill can't)

- Matt, Rustyarcade.com

Snubby
Snubby
  • Member since: Dec. 4, 2004
  • Offline.
Forum Stats
Member
Level 21
Game Developer
Response to AS: Math - Intermediate May. 28th, 2006 @ 05:02 PM Reply

I don't undertand that last bit about ++ as opposed to += 1 and stuff.

dELtaluca
dELtaluca
  • Member since: Apr. 16, 2004
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS: Math - Intermediate Jun. 22nd, 2006 @ 04:58 PM Reply

At 12/18/05 03:49 PM, mb3 wrote: this is how you could explain the shift thingy:
x << y = x * (y * 2)
x >> y = x / (y * 2)
i think that would be alot more easy.

actually, that is not correct

x << y = x * (2^y)
x >> y = x * (2^-y) or x / (2^y)

and ofcourse, this is very fast, because it deals with integers

so 3 >> 1 = (1.5) 1
5 >> 2 = (2.5) 2 >> 1 = 1


using ShamelessPlug; NapePhysicsEngine.advertise();

BBS Signature