NumericSuffixes
Shorthand numeric conversions.
Contents
Installation
This package is registered in METADATA.jl
and so can be installed using Pkg.add
Pkg.add("NumericSuffixes")
Public Interface
NumericSuffixes
— Module.Provides the @suffix
macro for generating shorthand numeric conversion suffixes.
Examples
x = 1i8 # Convert `1` to `Int8`.
y = 3u32 # Convert `3` to `UInt32`.
z = (x + y)r16 # Convert `4` to `Float16`.
Default Suffixes
16 suffixes are provided by default:
i8 --> Int8
i16 --> Int16
i32 --> Int32
i64 --> Int64
i128 --> Int128
u8 --> UInt8
u16 --> UInt16
u32 --> UInt32
u64 --> UInt64
u128 --> UInt128
r16 --> Float16
r32 --> Float32
r64 --> Float64
c32 --> Complex32
c64 --> Complex64
c128 --> Complex128
Additional user defined suffixes can be made using the @suffix
macro.
NumericSuffixes.@suffix
— Macro.Generate a new numeric suffix named n
which converts numbers to type T
.
Signature
@suffix n T
Examples
@suffix i8 Int8
x = 1i8
typeof(x) == Int8
More complex conversions can be made using anonymous function syntax:
@suffix t16 x -> trunc(Int16, x)
x = 1.2t16
typeof(x) == Int16
Default Suffixes
Signed Integers
NumericSuffixes.i8
— Type.Numeric suffix for Int8
values.
NumericSuffixes.i16
— Type.Numeric suffix for Int16
values.
NumericSuffixes.i32
— Type.Numeric suffix for Int32
values.
NumericSuffixes.i64
— Type.Numeric suffix for Int64
values.
NumericSuffixes.i128
— Type.Numeric suffix for Int128
values.
Unsigned Integers
NumericSuffixes.u8
— Type.Numeric suffix for UInt8
values.
NumericSuffixes.u16
— Type.Numeric suffix for UInt16
values.
NumericSuffixes.u32
— Type.Numeric suffix for UInt32
values.
NumericSuffixes.u64
— Type.Numeric suffix for UInt64
values.
NumericSuffixes.u128
— Type.Numeric suffix for UInt128
values.
Floating Point Numbers
NumericSuffixes.r16
— Type.Numeric suffix for Float16
values.
NumericSuffixes.r32
— Type.Numeric suffix for Float32
values.
NumericSuffixes.r64
— Type.Numeric suffix for Float64
values.
Complex Floating Point Numbers
NumericSuffixes.c32
— Type.Numeric suffix for Complex{Float16}
values.
NumericSuffixes.c64
— Type.Numeric suffix for Complex{Float32}
values.
NumericSuffixes.c128
— Type.Numeric suffix for Complex{Float64}
values.