# Difference between revisions of "Kray3 SDK/Arithmetic operations"

m (→Add) |
m |
||

Line 6: | Line 6: | ||

You can perform '''ADD''' operation on doubles, strings and vectors. | You can perform '''ADD''' operation on doubles, strings and vectors. | ||

− | <include highlight="kray3" select="3- | + | <include highlight="kray3" select="3-9" src="http://www.kraytracing.com/pub/kray3_script/operators.kray" /> |

{{Runkray3live|path=operators.kray}} | {{Runkray3live|path=operators.kray}} | ||

## Revision as of 15:15, 13 August 2012

## Contents

# Arithmetic operations

Several standard arithmetic operations can be used inside Kray script.

## Add

You can perform **ADD** operation on doubles, strings and vectors.

<include highlight="kray3" select="3-9" src="http://www.kraytracing.com/pub/kray3_script/operators.kray" />

## Subtract

You can perform **SUBTRACT** operation on doubles and vectors.

echo 2-2; 0 echo (1,2,3)-(3,2,1); (-2,0,2)

### Unary -

Unary operations can also be performed on doubles and vectors.

echo -(2); -2 echo -(1,2,3); -(1,2,3)

## Division

Can be performed on double, axes/axes, vector/axes, vector/vector.

9/7; 1.28571 <2,0,0>/<0,4,0>; // division is multiplication by reverse axes (reverse 3x3 matix) <2.00121,-3.99938,-983> (1,2,3)/<0,1,0>; // same as above (1,2.05205,2.96463) <>/<1,2,3>; // reverse transform to <1,2,3>; <-0.94745,-2.02541,-2.9829> (1,2,3)/(1,2,3); (1,1,1)

## Modulo

Modulo (%) can be performed on doubles.

```
123%100;
23
```

## Power

^ to the power of operator works on doubles.

```
2^24;
16777216
```

## Comparision

You can use comparision operators < > <= >= on doubles, strings.

2>3; 0 'Elephant'<'Zebra'; // alphabetical order comparation 1

You can use comparision operators == != on doubles, strings, vectors and axes.

2==1; // not true, returns 0 0 'String'!='string'; // its case sensitive String (1,2,3)==(1,2,3); 0 (1,2,3)!=(1,2,3); (1,2,3) <>!=<0>; <>

## Negation

! negation works on doubles.

!(2==2); // same as 2!=2 0 !!23; // converts any non zero value to 1 and leaves 0 as 0"; 1

## Logic operators

And (&) Or (|) logic operators can be used on doubles.

2|3; // bitwise 3 2&3; 2

## Concatenation

Concatenation operators work on doubles, vectors, strings.

((1,2),(3,4)); (1,2,3,4) ('string1','string2'); // for strings, same as + string1string2

## Convert vector>axis

<> converts vector to axis.

```
<(1,2,3)>;
<1,2,3>
```

## Exponential operator

E - exponential operator.

2e3; // same as 2*10^3 2000 (2+1)e(2*2); // also possible 30000 2e-2; 0.02