This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Numbers & arithmetic

Numbers are 64-bit floats, Int is a 64-bit integer, and Bool holds truth values. Run a cell to see its output beside the expected one.

Integer literals are floats

10 is read as 10.0, so division never truncates.

Viv [1]

print vs show

print gives the bare value. show labels a variable with its name, and prints any other expression bare, as print would.

Viv [2]

Scientific notation

Viv [3]

Compound assignment

x += 1 means x = x + 1, and the same holds for -=, *= and /=.

Viv [4]

The math builtins

29 functions. pow, atan2, hypot, copysign and mod take two arguments, fma takes three, min and max take two or more, and fsum gives the correctly rounded sum of an array. mod is C's fmod.

Viv [5]

erf and gamma

The engines agree to double precision; gamma(5) is 4! and gamma(1/2) is √π.

Viv [6]

Precedence

Multiplication binds tighter than addition; parentheses override.

Viv [7]

Division by zero and sqrt of a negative

Following IEEE float rules, these give inf and nan instead of stopping the program.

Viv [8]

mod with negatives

mod is C's fmod: the result takes the sign of the first argument.

Viv [9]

round halves go away from zero

round follows C: halves round away from zero, so 2.5 gives 3 and -2.5 gives -3, not the nearest even number.

Viv [10]

pow(0, 0) is 1

pow(0, 0) returns 1, as C does.

Viv [11]

atan2 knows the quadrant

atan2(y, x) uses the signs of both arguments to return the angle in the correct quadrant.

Viv [12]

abs, min, max

Viv [13]

The hyperbolics and inverse trig

Viv [14]

% and // round toward minus infinity

a % b takes the sign of b and a // b is the floor of the quotient, as in Python, so a == (a // b) * b + a % b. mod(a, b) is C's fmod and keeps the sign of a.

Viv [15]

^ is pow

x ^ y is pow(x, y). It binds tighter than a minus on its left, so -3 ^ 2 is -9, and it groups from the right.

Viv [16]