Skip to content

Basic Arithmetic

Lucas Menezes edited this page Sep 22, 2020 · 3 revisions

Arithmetics

Headache supports Addition, Subtraction, Multiplying, Division implemented as inlines functions.

These operations use the +, -, * , / and / symbols respectively.

Divisions with zero present special behavior:

  • 0/0 will generate 0 as a result.
  • x/0 | x != 0 is undefined behavior

Due to 8 bit brainfuck's nature, operations with bytes are much faster than the ones with shorts.

Headache also presents ++ and --, also as it presents += and -=. They are not just for convenience, they are natively implemented in bytes and run much faster.

Additions and subtractions have overflow.

Test this example:

byte add(byte a, byte b){
	return (a+b) as byte;
}
byte sub(byte a, byte b){
	return (a-b) as byte;
}
byte mul(byte a, byte b){
	return (a*b) as byte;
}
byte div(byte a, byte b){
	return (a/b) as byte;
}
void println(byte a){
	@a;@"\n";
}
void main(){
	println(add(10 as byte,2 as byte));
	println(sub(10 as byte,2 as byte));
	println(mul(10 as byte,2 as byte));
	println(div(10 as byte,2 as byte));
	
}
Clone this wiki locally