Binary Operators - ArdaOzcan/Boink GitHub Wiki

Table of Contents

Binary Operators

Plus

+ operator adds two types.

Supported and resulting types:

  • string + string = string
  • int + int = int
  • int + float = float
  • int + double = double
  • float + float = float
  • float + double = double
  • double + double = double

Examples:

int new = "hello " + "world" # 'new' is "hello world"
int new = 1 + 2 # 'new' is 3
float new = 1 + 2.0f # 'new' is 3.0f
double new = 1 + 2.0 # 'new' is 3.0

Minus

- operator subtracts two numerical types.

Supported and resulting types:

  • int - int = int
  • int - float = float
  • int - double = double
  • float - float = float
  • float - double = double
  • double - double = double

Examples:

int new = 1 - 2 # 'new' is -1
float new = 1 - 2.0f # 'new' is -1.0f
double new = 1 - 2.0 # 'new' is -1.0
double new = 1.0 - 2.0 # 'new' is -1.0

Slash

/ operator divides two numerical types.

Supported and resulting types:

  • int / int = double
  • int / float = float
  • int / double = double
  • float / float = float
  • float / double = double
  • double / double = double

Examples:

double new = 1 / 2 # 'new' is 0.5
float new = 1 / 2.0f # 'new' is 0.5f
double new = 1.0 / 2 # 'new' is 0.5
double new = 1.0 / 2.0 # 'new' is 0.5

Star

* operator multiplies two numerical types.

Supported and resulting types:

  • int * int = int
  • int * float = float
  • int * double = double
  • float * float = float
  • float * double = double
  • double * double = double

Examples:

int new = 3 * 2 # 'new' is 6
float new = 3 * 2.0f # 'new' is 6.0f
double new = 3 * 2.0 # 'new' is 6.0
float new = 3.0f * 2.0f # 'new' is 6.0f

Ampersand Ampersand

&& operator performs an and operation to two boolean types.

Supported and resulting types:

  • bool && bool = bool

Examples:

bool new = true && false # 'new' is false

Pipe Pipe

|| operator performs an or operation to two boolean types.

Supported and resulting types:

  • bool || bool = bool

Examples:

bool new = true || false # 'new' is true