Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL

4: Numb3rs > Books - Pg. 65

Numb3rs Notice the use of a double underscore before and after the keyword complex. The variable z, defined so, has now a real and an imaginary part that can be individually addressed using the syntax: __real__ z and __imag__ z respectively. Similarly, the next declaration produces a complex variable of 16-bit integer type: __complex__ int x; 65 Complex constants are easily created adding the suffix i or j, as in the following examples: x = 2 3j; z = 2.0f 3.0fj; All standard arithmetic operations (, , *, /) are performed correctly on complex data types. Additionally the "~" operator produces the complex conjugate. Complex types could be pretty handy in some types of applications, making the code more readable and helping avoid trivial errors. Unfortunately, as of this writing, the MPLAB IDE support of complex variables during debugging is only partial, giving access only to the real part through the Watches window and the mouse-over function.