Repository navigation
Modern Math Complex Operators
Paul Squires edited this page Oct 19, 2026
·
5 revisions
Home › Math Library › Math Library › Complex operators
Adds, subtracts, multiplies, divides, raises and compares complex numbers.
operator + ( byref a as Complex, byref b as Complex ) as Complex
operator + ( byref z as Complex, byval x as float64 ) as Complex
operator + ( byval x as float64, byref z as Complex ) as Complex
'' - * / ^ likewise, and unary -
operator = ( byref a as Complex, byref b as Complex ) as boolean
operator = ( byref z as Complex, byval x as float64 ) as boolean
operator = ( byval x as float64, byref z as Complex ) as boolean
'' <> likewise, in all three arrangements-
Every operator has all three arrangements —
ComplexwithComplex,float64withComplex,Complexwithfloat64. That is why there is noCAddReal/CMulImagfamily:z + 3.0andz * 2.0already say it, and better. -
Division uses Smith's formula, in all three overloads. The naive
(ac+bd)/(c²+d²)overflows its denominator once the components pass about1.3e154, where the true quotient is an ordinary number. - Multiplication is the plain four-multiply form, matching .NET. C99's infinity-recovery path is deliberately not implemented — it costs a branch on every multiply for a case that only arises in deliberate infinity arithmetic.
-
^isCPow.z ^ 2.0,z ^ wand2.0 ^ zall resolve to it. -
z = 3.0means equal to the real number and on the real axis — the imaginary part must be exactly zero. Either sign of zero counts, because-0.0 = 0.0as numbers. -
No
<><=>=. There is no ordering on ℂ. The same reasoning declined lexicographic ordering on tuples.
#import "std/numeric"
using numeric
dim as Complex a = CSet( 3, 4 ), b = CSet( -1, 2 )
print CToString( a + b ) '' 2+6i
print CToString( a * b ) '' -11+2i
print CToString( a / b ) '' 1-2i
print CToString( a + 2.0 ) '' 5+4i -- the mixed form
print CToString( 2.0 - a ) '' -1-4i
print CToString( a ^ 2.0 ) '' -6.999999999999998+24.000000000000004i
print a = CSet( 3, 4 ) '' true
print a <> b '' true
print CSet( 3, 0 ) = 3.0 '' true -- on the real axis, and equal
print CSet( 3, 1 ) = 3.0 '' false -- equal real part, but not on the axisLibrary: Math Library
Category: Math Library
Documented under: Members
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing