You are here: Math Resources > Operators in Spin

Operators in Spin

The following operators are available in Spin. There is a separate table for Operators in Propeller Assembly.

Spin Math and Logic Operators

Operator

Assignment Usage

Constant Expressions1

Is Unary

Description

Integer

Float

=

always

n/a1

n/a1

 

Constant assignment (CON blocks only)

:=

always

n/a1

n/a1

 

Variable assignment (PUB/PRI blocks only)

+ +=

ü

ü

 

Add

+

never

ü

ü

ü

Positive (+X); unary form of Add

- -=

ü

ü

 

Subtract

-

if solo

ü

ü

ü

Negate (-X); unary form of Subtract

--

always

 

 

ü

Pre-decrement (--X) or post-decrement (X--)

++

always

 

 

ü

Pre-increment (++X) or post-increment (X++)

* *=

ü

ü

 

Multiply and return lower 32 bits (signed)

** **=

ü

 

 

Multiply and return upper 32 bits (signed)

/ /=

ü

ü

 

Divide (signed)

// //=

ü

 

 

Modulus (signed)

#> #>=

ü

ü

 

Limit minimum (signed)

<# <#=

ü

ü

 

Limit maximum (signed)

^^

if solo

ü

ü

ü

Square root

||

if solo

ü

ü

ü

Absolute value

~

always

 

 

ü

Sign-extend from bit 7 (~X) or post-clear to 0 (X~); all bits low

~~

always

 

 

ü

Sign-extend from bit 15 (~~X) or post-set to -1 (X~~); all bits high

~> ~>=

ü

 

 

Shift arithmetic right

?

always

 

 

ü

Random number forward (?X) or reverse (X?)

|<

if solo

ü

 

ü

Bitwise: Decode value (0 - 31) into single-high-bit long

>|

if solo

ü

 

ü

Bitwise: Encode long into value (0 - 32) as high-bit priority

<< <<=

ü

 

 

Bitwise: Shift left

>> >>=

ü

 

 

Bitwise: Shift right

<- <-=

ü

 

 

Bitwise: Rotate left

-> ->=

ü

 

 

Bitwise: Rotate right

>< ><=

ü

 

 

Bitwise: Reverse

& &=

ü

 

 

Bitwise: AND

| |=

ü

 

 

Bitwise: OR

^ ^=

ü

 

 

Bitwise: XOR

!

if solo

ü

 

ü

Bitwise: NOT

AND AND=

ü

ü

 

Boolean: AND (promotes non-0 to -1)

OR OR=

ü

ü

 

Boolean: OR (promotes non-0 to -1)

NOT

if solo

ü

ü

ü

Boolean: NOT (promotes non-0 to -1)

== ===

ü

ü

 

Boolean: Is equal

<> <>=

ü

ü

 

Boolean: Is not equal

< <=

ü

ü

 

Boolean: Is less than (signed)

> >=

ü

ü

 

Boolean: Is greater than (signed)

=< =<=

ü

ü

 

Boolean: Is equal or less (signed)

=> =>=

ü

ü

 

Boolean: Is equal or greater (signed)

@

never

ü

 

ü

Symbol address

@@

never

 

 

ü

Object address plus symbol

Note 1: Assignment forms of operators are not allowed in constant expressions.

 

Propeller Help Version 1.1

Copyright © Parallax Inc.

5/13/2009