-
-
Notifications
You must be signed in to change notification settings - Fork 4
number
Number is an abstract type in Angle.
It encapsulates integer float (real) bignum natural rational and complex numbers
as well as primitive/internal types bool, byte (unsigned int8), int32, i64 (always signed), leb128 and smart pointers : int28 and int60
The internal number types are mostly isolated from the user facing number
type, which handles automatic casting,
up and downgrading between all different kinds of numbers: integers, reals, rational and complex numbers. Developers can
unknowingly accept an int8 and return a bignum pointer if their calculation grows out of hand. Unless they really want
all they need is number as parameter or variable type. Or no type at all if they rely on type inference
Number is usually the only type users should care about:
fibonacci number = if number<2 : 0 else fibonacci(number - 1) + fibonacci it - 2
They can even is_declared the number type if they want to let the auto-type compiler figure the signatures out
fib := if it<2 : 0 else fib(it-1) + fib it - 2
Only in specific situations, when accessing other APIs or system calls should specific types become relevant.
If developers interact with different types, the integration (casting) should be made seamless by the compiler.
Upcasting always works and downcasting may is_declared a warning.
int28 supports automatic upgrading to int60 in case of overflows.
JavaScript Numbers are doubles, that is, 64-bit floating-point values. Such a value can contain any 32-bit integer with full precision, but not all 64-bit ones. WebAssembly, on the other hand, has full support for 64-bit integers, the i64 type. https://v8.dev/features/wasm-bigint For connecting the two we now have the wasm BigInt supported in mayor browsers: JavaScript BigInts can be read or written from WebAssembly memory using the BigInt proposal's BigInt64Array or BigUint64Array In this way javascript BigInts are supported by all common desktop wasm browsers.
(unsigned) int16 (previously known as ‘word’) might be added for DOS legacy later.
Internally numbers are always assigned to the smallest type for efficiency: i32*i32=>i64 without overflow check.
as in julia and math, a number next to an object means multiplication:
3x == 3*x
we have a problem with significant whitespace though:
3 x == [3 x]
as defined by commaless list semantics
this should be a typical case of ambiguity handled by the compiler by asking the user to specify the intent
since the first case is unambivalent it works out of the box and is especially useful for units:
3km+10m = 3010 meters
Special user types such as phone number
and License plate number
should be of no conflict to the built-in abstract type.
this would be hard to achieve and currently the easiest workaround is to drop the number word in those cases or hyphen it