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

Gotchas

Float facts and Viv-specific surprises, each shown by a program that runs. Run a cell to see its output beside the expected one.

Float equality is a trap

0.1 + 0.2 is not 0.3 in binary floating point; compare with a tolerance instead. (Integers are another matter: a double holds them exactly up to 2^53, so n == 1.0 on a counter is an exact test.)

Viv [1]

The printer rounds to 6 significant digits

show uses %g formatting; the stored value is full double precision even when the print looks tidy.

Viv [2]

eig_sym does not check symmetry

Feed it a non-symmetric matrix and it computes something — for [[1,5],[0,2]] the true eigenvalues are 1 and 2, and this is not them. Symmetrize first.

Viv [3]

Copying an array means allocating one

Because assignment aliases, copying the data takes copy(a), which allocates a new array with the same entries.

Viv [4]

Adding 1 to 1e16 loses the 1

In exact arithmetic both lines would print 1; here both print 0. A double carries about 16 significant digits, so the 1 is rounded away when it meets 1e16, whichever way the sum is grouped.

Viv [5]

Catastrophic cancellation

At x = 1e12, sqrt(x+1) - sqrt(x) subtracts two nearly equal numbers and keeps only 5 correct digits; the rewrite 1 / (sqrt(x+1) + sqrt(x)) has no subtraction and gets them all.

Viv [6]