From 83f58e1da5bc711e6d11b49c2c659189a0112f5e Mon Sep 17 00:00:00 2001 From: pca006132 Date: Thu, 17 Dec 2020 14:52:24 +0800 Subject: [PATCH] added notes about numeric types --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index beca8f4..5e44fda 100644 --- a/README.md +++ b/README.md @@ -58,13 +58,14 @@ class Foo(EnvExperiment): ## Built-in Types * Primitive types include: * `bool` + * `byte` * `int32` * `int64` * `uint32` * `uint64` * `float` * `str` (note: fixed length, provide builtin methods?) - * `bytes` + * `bytes` (a list of `byte`, but with more convenient syntax) * Collections include: * `list`: homogeneous (elements must be of the same type) fixed-size (no append) list. @@ -83,6 +84,16 @@ class Foo(EnvExperiment): ``` * `range` (over numerical types) +### Numerical Types +* All binary operations expect the values to have the same type, no implicit + coercion would be performed, explicit casting is required. +* Casting can be done by `T(v)` where `T` is the target type, and `v` is the + original value. Examples: `int64(123)` +* Constant integers are treated as `int32` by default. If the value cannot + be stored in `int32`, `uint64` would be used if the integer is non-negative, + and `int64` would be used it the integer is negative. +* Only `uint32`, `int32` (and range of them) can be used as index. + ## Generics We use [type variable](https://docs.python.org/3/library/typing.html#typing.TypeVar) for denoting generics.