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/SOUL_Language.md
+19Lines changed: 19 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -147,6 +147,9 @@ The primitive types currently supported are:
147
147
-`float32` - 32-bit float type
148
148
-`float64` - 64-bit float type
149
149
-`float` - fastest floating-point type that provides at least 32-bit precision
150
+
-`complex32` - 32-bit complex type
151
+
-`complex64` - 64-bit complex type
152
+
-`complex` - fastest complex type that provides at least 32-bit precision
150
153
-`wrap<size>` - a range-constrained `int32` type. The `size` value must be a compile-time constant, and operations on this type are guaranteed to result in values where 0 <= x < size. If incrementing or decrementing it, out-of-range values will wrap around.
151
154
-`clamp<size>` - similar to `wrap<size>` but out-of-range values are clamped rather than wrapped
152
155
-`string` - a character literal. These can be passed around but no operations which could incur runtime allocation are possible (i.e. concatenation, etc), and slicing/indexing is not supported - the main purpose of string literals and this type is for use in debug logging functions.
For a 32-bit float, you can use either `f` or `f32` as the suffix, e.g. `123.0f` or `123.0f32`.
168
171
For 64-bit floats, either write it without a suffix, or use `f64`, `123.0` or `123.0f64`
169
172
For readability, you can also add an underscore before any of these suffixes, e.g. `123.0_f64`
173
+
-##### Complex numbers
174
+
Complex numbers are made from a real and imaginary component. The real component uses the same syntax as the assocated floating point formats (so `f` or `f32` to indicate a 32 bit floating point value) whilst imaginary numbers are specified using the `fi` or `f32i` suffix for 32 bit imaginary components, or `i` or `f64i` for 64 bit imaginary components. Complex constants with both real and imaginary components can be declared by adding these components together, for example `1.2f + 3.4fi`
170
175
-##### Boolean
171
176
`true` and `false` are built-in keywords
172
177
@@ -307,6 +312,20 @@ Dynamic slices are handled internally as a "fat pointer", i.e. a pointer + size,
307
312
308
313
Slices may be left uninitialised, in which case they have a size of zero and any access will return a value of 0 (in whatever element type they're using).
309
314
315
+
#### Complex components
316
+
317
+
As complex numbers are primitives, vectors and arrays of complex numbers can be constructed. The real and imaginary components of the complex number can be retrieved using the `.real` and `.imag` accessors respectively. For a complex vector, these accessors will return a vector of real or imaginary components.
318
+
319
+
```C++
320
+
let c = 1.0f + 2.0fi; // c is a complex32 with real: 1.0f, imag: 2.0f
321
+
let d = c * c; // d is a complex32 with real: -3.0f, imag: 4.0f
322
+
let e = d.real; // e is a float32 with value -3.0f
323
+
let f = d.imag; // f is a float32 with value 4.0f
324
+
325
+
complex64<4> g = 1.0; // vector of 4 complex64 with real: 1.0, imag: 0.0
326
+
let h = g.real; // vector of 4 float64 all with value 1.0
327
+
```
328
+
310
329
#### 'External' variables
311
330
312
331
Sometimes a processor needs to randomly-access large blocks of read-only data (e.g. for audio samples, etc), or to allow the runtime API to provide other constants which aren't part of the source code. To allow the app to get this data across to the SOUL program, the `external` qualifier can be added to a variable.
0 commit comments