Category talk:Wren-complex: Difference between revisions

m
→‎Source code: Now uses Wren S/H lexer.
(→‎Source code: Added support for complex matrices.)
m (→‎Source code: Now uses Wren S/H lexer.)
 
(4 intermediate revisions by the same user not shown)
Line 9:
===Source code===
 
<langsyntaxhighlight ecmascriptlang="wren">/* Module "complex.wren" */
 
import "./trait" for Cloneable
 
/* Complex represents a complex number of the form 'a + bi' where 'a' and 'b'
Line 35:
static one { Complex.new_( 1, 0) }
static two { Complex.new_( 2, 0) }
static tau three { Complex.new_(1.6180339887498948482 3, 0) } // synonym for phi
static four { Complex.new_( 4, 0) }
static five { Complex.new_( 5, 0) }
static six { Complex.new_( 6, 0) }
static seven { Complex.new_( 7, 0) }
static eight { Complex.new_( 8, 0) }
static nine { Complex.new_( 9, 0) }
static ten { Complex.new_(10, 0) }
static imagMinusOne { Complex.new_( 0, -1) }
static imagOne { Complex.new_( 0, 1) }
static imagTwo { Complex.new_( 0, 2) }
static imagThree { Complex.new_( 0, 3) }
static imagFour { Complex.new_( 0, 4) }
static imagFive { Complex.new_( 0, 5) }
static imagSix { Complex.new_( 0, 6) }
static imagSeven { Complex.new_( 0, 7) }
static imagEight { Complex.new_( 0, 8) }
static imagNine { Complex.new_( 0, 9) }
static imagTen { Complex.new_( 0, 10) }
static i { Complex.new_( 0, 1) } // same as imagOne
static pi { Complex.new_(Num.pi, 0) }
static tau { Complex.new_(Num.tau, 0) }
static e { Complex.new_(2.71828182845904523536, 0) }
static phi { Complex.new_(1.6180339887498948482, 0) } // golden ratio
static tau { Complex.new_(1.6180339887498948482, 0) } // synonym for phi
static ln2 { Complex.new_(0.69314718055994530942, 0) } // 2.log
static ln10 { Complex.new_(2.30258509299404568402, 0) } // 10.log
Line 950 ⟶ 964:
static sum(a) { a.reduce { |acc, x| acc + x } }
static prod(a) { a[1..-1].reduce(a[0]) { |acc, x| acc * x } }
}</syntaxhighlight>
}
 
// Type aliases for classes in case of any name clashes with other modules.
var Complex_Complex = Complex
var Complex_Complexes = Complexes
var Complex_CMatrix = CMatrix
var Complex_CMatrices = CMatrices
var Complex_Cloneable = Cloneable // in case imported indirectly</lang>
9,479

edits