.. _language-libraries: Libraries ========= Libraries are imported by enclosing the name of the library with angled brackets. .. code-block:: csl /// main.csl const math = @import_module(""); fn distance(x0 : f16, y0 : f16, x1 : f16, x1 : f16) f16 { return math.sqrt((x0-x1)*(x0-x1) + (x0-x1)*(x0-x1)); } .. _language-libraries-complex: ----------- The complex library provides structs containing ``real`` and ``imag`` components and basic complex functions. ``complex`` is a generic struct parameterized by its field type. The ``complex_32`` and ``complex_64`` non-generic names are also provided; these define a complex number using two ``f16`` values and a complex number using two ``f32`` values, respectively. ``get_complex`` is a generic constructor that returns a complex struct based on the type of its inputs. The non-generic ``get_complex_32`` and ``get_complex_64`` constructor functions are provided as well: .. code-block:: csl // Returns struct {real: T, imag: T} where T can be f16 or f32 fn complex(comptime T: type) type const complex_32 = complex(f16); // struct {real: f16, imag: f16} const complex_64 = complex(f32); // struct {real: f32, imag: f32} // Can operate on f16 or f32 fn get_complex(r: anytype, i: @type_of(r)) complex(@type_of(r)) fn get_complex_32(r : f16, i : f16) complex_32 fn get_complex_64(r : f32, i : f32) complex_64 The following functions are provided for operating on complex numbers. They are written as generic functions to facilitate use in other libraries or abstractions. In addition, non-generic ``complex_32`` and ``complex_64`` functions are provided. These functions have names suffixed with ``_32`` and ``_64``, respectively. .. code-block:: csl // x, y can be complex_32 or complex_64 fn add_complex(x: anytype, y: @type_of(x)) @type_of(x) fn subtract_complex(x: anytype, y: @type_of(x)) @type_of(x) fn multiply_complex(x: anytype, y: @type_of(x)) @type_of(x) .. _language-libraries-debug: ----------- The debug library provides a tracing mechanism to record tagged values. .. code-block:: csl // Record values of the specified type fn trace_bool(x : bool) void fn trace_u8(x : u8) void fn trace_i8(x : i8) void fn trace_u16(x : u16) void fn trace_i16(x : i16) void fn trace_f16(x : f16) void fn trace_u32(x : u32) void fn trace_i32(x : i32) void fn trace_f32(x : f32) void // Record a compile-time string fn trace_string(comptime str : comptime_string) void // Generic version fn trace(x : anytype) void // Record timestamp using the