- Julia 1.0 Programming Complete Reference Guide
- Ivo Balbaert Adrian Salceanu
- 327字
- 2021-06-24 14:21:41
Integers
Julia offers support for integer numbers ranging from types Int8 to Int128, with 8 to 128 representing the number of bits used, and with unsigned variants with a U prefix, such as UInt8. The default type (which can also be used as Int) is Int32 or Int64, depending on the target machine architecture. The bit width is given by the Sys.WORD_SIZE variable. The number of bits used by the integer affects the maximum and minimum value this integer can have. The minimum and maximum values are given by the typemin() and typemax() functions, respectively; for example, typemax(Int16) returns 32767.
If you try to store a number larger than that allowed by typemax, overflow occurs. For example, note the following:
julia> typemax(Int)
9223372036854775807 # might be different on 32 bit platform
julia> ans + 1
-9223372036854775808
Overflow checking is not automatic, so an explicit check (for example, the result has the wrong sign) is needed when this can occur. Integers can also be written in binary (0b), octal (0o), and hexadecimal (0x) format.
For computations needing arbitrary-precision integers, Julia has a BigInt type. These values can be constructed as BigInt(number) or big(number), and support the same operators as normal integers. Conversions between numeric types are automatic, but not between the primitive types and the big types. The normal operations of addition (+), subtraction (-), and multiplication (*) apply for integers. A division (/) always gives a floating point number. If you only want integer divisor and remainder, use div and rem. The symbol ^ is used to obtain the power of a number.
The logical values, true and false, of type Bool are also integers with 8 bits. 0 amounts to false, and 1 to true. Negation can be done with the ! operator; for example, !true is false. Comparing numbers with == (equal), != or < and > returns a Bool value, and comparisons can be chained after one another (as in 0 < x < 3).
- The Modern C++ Challenge
- 程序員數(shù)學(xué):用Python學(xué)透線性代數(shù)和微積分
- PyTorch Artificial Intelligence Fundamentals
- C語言程序設(shè)計教程(第2版)
- Clojure for Domain:specific Languages
- C語言最佳實踐
- 機器人Python青少年編程開發(fā)實例
- Internet of Things with Intel Galileo
- 高級C/C++編譯技術(shù)(典藏版)
- JavaScript動態(tài)網(wǎng)頁開發(fā)詳解
- Learning Vaadin 7(Second Edition)
- Protocol-Oriented Programming with Swift
- Learning Modular Java Programming
- Java Web應(yīng)用開發(fā)給力起飛
- 深度實踐KVM:核心技術(shù)、管理運維、性能優(yōu)化與項目實施