You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tutorial.md
+21-3Lines changed: 21 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,12 +72,12 @@ Note for Lua users: Lua lets one variable hold different kinds of values over ti
72
72
73
73
| Type | What it is | Example values |
74
74
|------|------------|----------------|
75
-
|`i32`| A whole number (integer) |`42`, `-7`, `0`|
76
-
|`f32`| A decimal number (float) |`3.14`, `-0.5`, `1.0`|
75
+
|`i32`| A whole number (integer) |`42`, `-7`, `0`, `42i32`|
76
+
|`f32`| A decimal number (float) |`3.14`, `-0.5`, `1.0`, `1.0f32`|
77
77
|`bool`| True or false |`true`, `false`|
78
78
|`str`| Text (a string in quotes) |`"hello"`|
79
79
|`i8`| A very small whole number, used for individual characters |`65` (the letter `A`) |
80
-
|`u32`| A whole number that cannot be negative (unsigned) |`42`, `0`|
80
+
|`u32`| A whole number that cannot be negative (unsigned) |`42u32`, `42u`, `0u32`|
81
81
82
82
Single characters can also be written with single quotes: `'a'`, `'Z'`, `'\n'` (newline). This is called a character literal.
83
83
@@ -103,6 +103,24 @@ In audio and DSP work, you will use `f32` constantly. Audio signals, frequencies
103
103
104
104
**A note on `f64`:** The language grammar also defines an `f64` type, which is a higher-precision decimal number. In Audulus DSP work, `f32` is the type you'll usually use.
105
105
106
+
By default, whole-number literals are `i32`, and decimal literals are `f32`.
107
+
108
+
### Numeric literal suffixes
109
+
110
+
Numeric literals can include a type suffix when you need the literal itself to have a specific type:
111
+
112
+
```lyte
113
+
main {
114
+
var count = 1i32
115
+
var mask = 1u32
116
+
var also_unsigned = 1u
117
+
var gain = 1.0f32
118
+
var precise = 1.0f64
119
+
}
120
+
```
121
+
122
+
Use `as` when converting an existing value or expression from one type to another, such as `x as i32` or `(len - 2) as f32`.
123
+
106
124
### Why does static typing matter?
107
125
108
126
In audio DSP, you are doing a lot of math very quickly. If the language has to keep figuring out what kind of value something is while it runs, that adds overhead. By knowing the types up front, Lyte can build faster code. Here, **compile** just means “turn your code into something the computer can run.”
0 commit comments