Content deleted Content added
m Improve license text, link, and citation |
Re add the matrix section; add missing links |
||
Line 66:
=== Explicit procedure overloading ===
Odin has [[Function_overloading|procedure overloading]], but unlike C++
<syntaxhighlight lang="go">
bool_to_string :: proc(b: bool) -> string {...}
Line 87:
</syntaxhighlight>
The language also features "swizzling" of arrays, similar to the operation in shader languages like GLSL<ref>https://www.khronos.org/opengl/wiki/Data_Type_(GLSL)#Swizzling</ref>.
<syntaxhighlight lang="go">
Line 107:
}
</syntaxhighlight>
====Matrix support====
A <code>matrix</code> is a [[Matrix_(mathematics)|mathematical type]] built into Odin. It is a regular array of numbers, arranged in rows and columns. Odin's matrix support allows for ''matrix-array and matrix-matrix operations'' making it a [[Basic_Linear_Algebra_Subprograms#Level_3|Level 3 Basic Linear Algebra Subprogram]]ing language.
<syntaxhighlight>
a: matrix[2, 3]f32 // matrix that has 2 rows and 3 columns with an element type of f32
b: matrix[3, 2]f32 // matrix that has 3 rows and 2 columns with an element type of f32
v: [2]f32 // array that has 2 elements with an element type of f32
a = matrix[2, 3]f32{
1, 9, -13,
20, 5, -6,
}
b = matrix[3, 2]f32{
3, 5,
7, 9,
}
v = [2]f32{2, -4}
m := a * b // matrix-matrix multiplication
vp := m * v // matrix-array multiplication
</syntaxhighlight>
The internal representation of a <code>matrix</code> in Odin is stored in [[Row-_and_column-major_order|column-major]] format<ref>https://odin-lang.org/docs/overview/#matrix-type</ref> while the matrix literals are written in standard (row-major like) order (e.g. <code>matrix[2, 3]f32</code> is internally <code>[3][2]f32</code> (with different a [[Data_structure_alignment|alignment]] requirement)). Column-major is used in order to utilize ([[SIMD]]) vector instructions effectively on modern hardware, if possible.
==Comparisons with other languages==
Line 117 ⟶ 141:
* Introduces [[strong typing]]
* Adds array programming and improves [[Type introspection|runtime reflection]]
* Has explicit [[function overloading]]<ref>{{Cite web|title=Overview|url=https://odin-lang.org/docs/overview/|access-date=2021-11-15|website=odin-lang.org}}</ref>
Compared to Go, Odin:
|