Julia编程语言的新版本之所以受到整个人工智能界的关注,最主要的原因正是其将 C 语言的速度、Ruby 的灵活、Python 的通用性前所未有地结合在一起,支持并行处理,易于学习和使用,尤其适合科学和工程计算。
官方文档链接:
Julia Documentation · The Julia Language
软件下载链接:
▋〓〓特色〓〓▋溢出特征只针对Int64位有效
▋〓〓特色〓〓▋通过big函数表述大数
▋〓〓特色〓〓▋浮点数中有+0和-0。这两个数值相等但是有不同的二进制表示
▋〓〓特色〓〓▋特殊的浮点数
▋〓〓特色〓〓▋针对每一个浮点数,均可以输出其浮点数的精度范围
▋〓〓特色〓〓▋可以输出每一个浮点数的前一个浮点数和后一个浮点数
特色内容详见下文。
Julia原生数据类型如下:
- 整数类型(说明:表述风格接近C语言风格)
Type | Signed? | Number of bits | Smallest value | Largest value |
---|---|---|---|---|
Int8 | ✓ | 8 | -2^7 | 2^7 - 1 |
UInt8 | 8 | 0 | 2^8 - 1 | |
Int16 | ✓ | 16 | -2^15 | 2^15 - 1 |
UInt16 | 16 | 0 | 2^16 - 1 | |
Int32 | ✓ | 32 | -2^31 | 2^31 - 1 |
UInt32 | 32 | 0 | 2^32 - 1 | |
Int64 | ✓ | 64 | -2^63 | 2^63 - 1 |
UInt64 | 64 | 0 | 2^64 - 1 | |
Int128 | ✓ | 128 | -2^127 | 2^127 - 1 |
UInt128 | 128 | 0 | 2^128 - 1 | |
Bool | N/A | 8 | false (0) | true (1) |
- 浮点数类型(说明:表述风格接近C语言风格)
Type | Precision | Number of bits |
---|---|---|
Float16 | half | 16 |
Float32 | single | 32 |
Float64 | double | 64 |
我的笔记本为64位,安装的也为64位Julia软件。以下为测试情况。
整数
十进制整数测试
julia> typeof(1)
Int64
julia> Int
Int64
julia> UInt
UInt64
十六进制整数测试
julia> typeof(0x12)
UInt8
julia> typeof(0x1234)
UInt16
julia> typeof(0x12345678)
UInt32
julia> typeof(0x1234567812345678)
UInt64
julia> typeof(0x12345678123456781234567812345678)
UInt128
二进制整数测试
julia> typeof(0b11111111)
UInt8
julia> typeof(0b1111111111111111)
UInt16
julia> typeof(0b11111111111111111111111111111111)
UInt32
julia> typeof(0b1111111111111111111111111111111111111111111111111111111111111111)
UInt64
julia> typeof(0b11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111)
UInt128
最大最小值表述范围
julia> for T in [Int8,Int16,Int32,Int64,Int128,UInt8,UInt16,UInt32,UInt64,UInt128] println("$(lpad(T,7)):[$(typemin(T)),$(typemax(T))]") end
Int8:[-128,127]
Int16:[-32768,32767]
Int32:[-2147483648,2147483647]
Int64:[-9223372036854775808,9223372036854775807]
Int128:[-170141183460469231731687303715884105728,170141183460469231731687303715884105727]
UInt8:[0,255]
UInt16:[0,65535]
UInt32:[0,4294967295]
UInt64:[0,18446744073709551615]
UInt128:[0,340282366920938463463374607431768211455]
溢出特征
▋〓〓特色〓〓▋溢出特征只针对Int64位有效
julia> typemax(Int32)
2147483647
julia> typemax(Int32)+1
2147483648
julia> typemax(Int64)
9223372036854775807
julia> typemax(Int64)+1
-9223372036854775808
julia> typemax(Int64)+1 == typemin(Int64)
true
▋〓〓特色〓〓▋通过big函数表述大数
julia> 10^20
7766279631452241920
julia> big(10)^20
100000000000000000000
浮点数
典型示例
julia> 1.33e-4
0.000133
julia> typeof(1.33e-4)
Float64
julia> typeof(1.33f0)
Float32
▋〓〓特色〓〓▋浮点数中有+0和-0。这两个数值相等但是有不同的二进制表示。
julia> bitstring(0.0)
"0000000000000000000000000000000000000000000000000000000000000000"
julia> bitstring(-0.0)
"1000000000000000000000000000000000000000000000000000000000000000"
julia> 0.0 == -0.0
true
▋〓〓特色〓〓▋特殊的浮点数
Float16 | Float32 | Float64 | Name | Description |
---|---|---|---|---|
Inf16 | Inf32 | Inf | positive infinity | a value greater than all finite floating-point values |
-Inf16 | -Inf32 | -Inf | negative infinity | a value less than all finite floating-point values |
NaN16 | NaN32 | NaN | not a number | a value not == to any floating-point value (including itself) |
julia> bitstring(1/Inf)
"0000000000000000000000000000000000000000000000000000000000000000"
julia> bitstring(-1/Inf)
"1000000000000000000000000000000000000000000000000000000000000000"
julia> bitstring(-1/(-Inf))
"0000000000000000000000000000000000000000000000000000000000000000"
julia> bitstring(1/(-Inf))
"1000000000000000000000000000000000000000000000000000000000000000"
julia> bitstring(1/(-Inf+300))
"1000000000000000000000000000000000000000000000000000000000000000"
julia> bitstring(1/(-Inf-500))
"1000000000000000000000000000000000000000000000000000000000000000"
机器精度(说明:类似MATLAB表述)
julia> eps(Float32)
1.1920929f-7
julia> eps(Float64)
2.220446049250313e-16
▋〓〓特色〓〓▋针对每一个浮点数,均可以输出其浮点数的精度范围
julia> eps(0.0)
5.0e-324
julia> eps(-0.0)
5.0e-324
julia> eps(0.01)
1.734723475976807e-18
julia> eps(0.1)
1.3877787807814457e-17
julia> eps(1.0)
2.220446049250313e-16
julia> eps(1.00)
2.220446049250313e-16
▋〓〓特色〓〓▋可以输出每一个浮点数的前一个浮点数和后一个浮点数
julia> bitstring(1.25)
"0011111111110100000000000000000000000000000000000000000000000000"
julia> bitstring(prevfloat(1.25))
"0011111111110011111111111111111111111111111111111111111111111111"
julia> bitstring(nextfloat(1.25))
"0011111111110100000000000000000000000000000000000000000000000001"