Difference between revisions of "Larger and Smaller Operators"

From GiderosMobile
m (Text replacement - "<source" to "<syntaxhighlight")
 
(One intermediate revision by one other user not shown)
Line 6: Line 6:
 
Operators to return the larger or smaller of two values.
 
Operators to return the larger or smaller of two values.
  
a'''<>'''b &emsp; compares 'a' and 'b', returns the larger of them.
+
a'''<>'''b, compares 'a' and 'b', returns the larger of them
  
a'''><'''b &emsp; compares 'a' and 'b', returns the smaller of them.
+
a'''><'''b, compares 'a' and 'b', returns the smaller of them
  
 
=== Examples ===
 
=== Examples ===
Line 15: Line 15:
 
x=a<>b -- faster than x=math.max(a,b)
 
x=a<>b -- faster than x=math.max(a,b)
 
x=(x-1)<>5 -- decrement x, but don't go below 5
 
x=(x-1)<>5 -- decrement x, but don't go below 5
</source>
+
</syntaxhighlight>
  
 
'''Simple smaller examples'''
 
'''Simple smaller examples'''
Line 21: Line 21:
 
x=a><b -- faster than x=math.min(a,b)
 
x=a><b -- faster than x=math.min(a,b)
 
x=(x+1)><15 -- increment x, but don't go above 15
 
x=(x+1)><15 -- increment x, but don't go above 15
</source>
+
</syntaxhighlight>
  
 
'''Make sure x is within bounds example'''
 
'''Make sure x is within bounds example'''
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
x=(x<>min)><max
 
x=(x<>min)><max
</source>
+
</syntaxhighlight>
  
 
'''Always return the negative of a number'''
 
'''Always return the negative of a number'''
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
x=-x><x -- faster than -math.abs
 
x=-x><x -- faster than -math.abs
</source>
+
</syntaxhighlight>
  
 
'''Always return the positive of a number'''
 
'''Always return the positive of a number'''
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
x=-x<>x -- faster than math.abs
 
x=-x<>x -- faster than math.abs
</source>
+
</syntaxhighlight>
  
 
{{GIDEROS IMPORTANT LINKS}}
 
{{GIDEROS IMPORTANT LINKS}}

Latest revision as of 02:59, 1 December 2023

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

Description

Operators to return the larger or smaller of two values.

a<>b, compares 'a' and 'b', returns the larger of them

a><b, compares 'a' and 'b', returns the smaller of them

Examples

Simple larger examples

x=a<>b -- faster than x=math.max(a,b)
x=(x-1)<>5 -- decrement x, but don't go below 5

Simple smaller examples

x=a><b -- faster than x=math.min(a,b)
x=(x+1)><15 -- increment x, but don't go above 15

Make sure x is within bounds example

x=(x<>min)><max

Always return the negative of a number

x=-x><x -- faster than -math.abs

Always return the positive of a number

x=-x<>x -- faster than math.abs