Difference between revisions of "Mutation Operators"

From GiderosMobile
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
 
 
<!-- GIDEROSOBJ:Mutation Operators -->
 
<!-- GIDEROSOBJ:Mutation Operators -->
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]]<br/>
+
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]]<br/>
'''<translate>Available since</translate>:''' Gideros 2017.11<br/>
+
'''Available since:''' Gideros 2017.11<br/>
=== <translate>Description</translate> ===
 
<translate><br />
 
Operators to mutate a value.<br /><br />
 
  
a<b> += </b>b &emsp; Add 'b' to 'a'.<br />
+
=== Description ===
a<b> -= </b>b &emsp; Subtract 'b from 'a'.<br />
+
Operators to mutate a value.
a<b> *= </b>b &emsp; Multiply 'a' by 'b', result in 'a'.<br />
+
 
a<b> /= </b>b &emsp; Divide 'a' by 'b', result in 'a'.<br />
+
*a<b> += </b>b = add 'b' to 'a'
a<b> %= </b>b &emsp; The result of 'a%b' is placed in 'a'.<br />
+
*a<b> -= </b>b = subtract 'b from 'a'
a<b> ^= </b>b &emsp; The result of 'a^b' is placed in 'a'^ is faster than a=math.pow(a,b)<br />
+
*a<b> *= </b>b = multiply 'a' by 'b', result in 'a'
a<b> ^= </b>0.5 &emsp; The result is faster than a=math.sqrt(a)<br /></translate>
+
*a<b> /= </b>b = divide 'a' by 'b', result in 'a'
=== <translate>Examples</translate> ===
+
*a<b> %= </b>b = the result of 'a%b' is placed in 'a'
'''Simple larger example'''<br/>
+
*a<b> ^= </b>b = the result of 'a^b' is placed in 'a' ('''^ is faster than a=math.pow(a,b)''')
<source lang="lua">score+=1 -- faster and less typing than score=score+1</source>
+
*a<b> ^= </b>0.5 = the result is faster than a=math.sqrt(a)
<br/>'''"getDistance" function:'''
+
 
<source lang="lua">--Non-optimized variant (5x slower):
+
=== Examples ===
 +
'''Simple larger example'''
 +
<syntaxhighlight lang="lua">
 +
score+=1 -- faster and less typing than score=score+1
 +
</syntaxhighlight>
 +
 
 +
'''"getDistance" function''' ('''see also the new <big>[[Math.distance]]</big> function''')
 +
<syntaxhighlight lang="lua">
 +
--Non-optimized variant (5x slower):
 
function getDistance( x1, y1, x2, y2 )
 
function getDistance( x1, y1, x2, y2 )
return math.sqrt ( math.pow ( x2 - x1, 2 ) + math.pow ( y2 - y1, 2 ) )
+
return math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2))
 
end
 
end
  
 
--Optimized variant (5x faster):
 
--Optimized variant (5x faster):
function getDistance2( x1, y1, x2, y2 )
+
function getDistance2(x1, y1, x2, y2)
return ((x1 - x2)^2 + (y1 - y2)^2)^0.5
+
return ((x2 - x1)^2 + (y2 - y1)^2)^0.5
 
end
 
end
 +
</syntaxhighlight>
  
</source>
+
{{GIDEROS IMPORTANT LINKS}}
{|-
 
| style="width: 50%; vertical-align:top;"|
 
=== <translate>Methods</translate> ===
 
| style="width: 50%; vertical-align:top;"|
 
=== <translate>Events</translate> ===
 
=== <translate>Constants</translate> ===
 
|}
 

Latest revision as of 03:00, 1 December 2023

Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.png
Available since: Gideros 2017.11

Description

Operators to mutate a value.

  • a += b = add 'b' to 'a'
  • a -= b = subtract 'b from 'a'
  • a *= b = multiply 'a' by 'b', result in 'a'
  • a /= b = divide 'a' by 'b', result in 'a'
  • a %= b = the result of 'a%b' is placed in 'a'
  • a ^= b = the result of 'a^b' is placed in 'a' (^ is faster than a=math.pow(a,b))
  • a ^= 0.5 = the result is faster than a=math.sqrt(a)

Examples

Simple larger example

score+=1 -- faster and less typing than score=score+1

"getDistance" function (see also the new Math.distance function)

--Non-optimized variant (5x slower):
function getDistance( x1, y1, x2, y2 )
	return math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2))
end

--Optimized variant (5x faster):
function getDistance2(x1, y1, x2, y2)
	return ((x2 - x1)^2 + (y2 - y1)^2)^0.5
end