官术网_书友最值得收藏!

Rational and complex numbers

Julia supports these types out of the box. The global constant  im represents the square root of -1, so that 3.2 + 7.1im is a complex number with floating point coefficients, so it is of the type Complex{Float64}.

This is the first example of a parametric type in Julia. For this example, we can write this as Complex{T}, where type T can take a number of different type values, such as Int32, Int64, or Float64.

All operations and elementary functions, such as exp(), sqrt(), sinh(), real(), imag(), abs(), and so on, are also defined on complex numbers; for example, abs(3.2 + 7.1im) = 7.787810988975015.

If a and b are two variables that contain a number, use complex(a,b) to form a complex number with them. Rational numbers are useful when you want to work with exact ratios of integers, for example, 3//4, which is of type Rational{Int64}.

Again, comparisons and standard operations are defined: float() converts to a floating point number, and num() and den() gives the numerator and denominator. Both types work together seamlessly with all the other numeric types.

主站蜘蛛池模板: 襄樊市| 巩义市| 怀来县| 泰顺县| 靖远县| 潜江市| 利津县| 加查县| 吴江市| 庆阳市| 黄龙县| 海伦市| 正镶白旗| 嘉峪关市| 金坛市| 长武县| 汪清县| 睢宁县| 会同县| 栾城县| 察隅县| 自贡市| 凯里市| 甘南县| 罗甸县| 永平县| 佛冈县| 璧山县| 浦江县| 徐州市| 曲沃县| 哈巴河县| 浑源县| 河东区| 清苑县| 桃源县| 榆中县| 辽阳县| 金阳县| 砚山县| 册亨县|