Crash-tan Crash-tan

The tale of the missing operator...

Crash BASIC 1.49.4 Release Notes

written by Crash-tan

^ IS AN OPERATOR NOW

You can write powers the short way:

PRINT 2 ^ 3            ' 8
PRINT 9 ^ 0.5          ' 3  — square root
PRINT 2 ^ -1           ' 0.5
PRINT SQR(3^2 + 4^2)   ' 5

It's the same math POW has always done, and the two agree exactly: 2 ^ 10 and POW(2, 10) are the same 1024. Use whichever reads better in the line you're writing — neither is going anywhere.

How it binds

Two rules, and both are the ones BASIC has always used — so if you're coming from another BASIC, this is already in your fingers.

^ goes first. It binds tighter than everything else in arithmetic, so 2 * 3 ^ 2 is 18 — the square happens, then the multiply. Write (2 * 3) ^ 2 if you meant 36.

Tighter than the minus sign, too. -2 ^ 2 is -4, not 4. The exponent applies to the 2, and then the whole thing goes negative. This one surprises people in every BASIC, so it's worth reading twice. When you want a negative base squared, say so with parentheses: (-2) ^ 2 is 4.

And it stacks right-to-left, the way it does on paper: 2 ^ 3 ^ 2 is 2 ^ (3 ^ 2) — 2 to the 9th, 512. Not 64.

Nothing you've written will change

^ in arithmetic is brand new, so there's no program relying on an old meaning — every program that ran yesterday runs the same today.

And the ^ you already use elsewhere is untouched, because it was never the same ^. Ties in PLAY music strings still tie: PLAY "L4 C^16 D E" holds that C exactly as long as it always did. Anchors in REGEX patterns still anchor: REGEX(email$, "^[\w.-]+@[\w.-]+\.[a-z]{2,}$") matches what it always matched. Those live inside quotes, and what's inside your quotes is yours.