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

NumericSuffixesModule.

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.

source

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
source

Default Suffixes

Signed Integers

Numeric suffix for Int8 values.

source

Numeric suffix for Int16 values.

source

Numeric suffix for Int32 values.

source

Numeric suffix for Int64 values.

source

Numeric suffix for Int128 values.

source

Unsigned Integers

Numeric suffix for UInt8 values.

source

Numeric suffix for UInt16 values.

source

Numeric suffix for UInt32 values.

source

Numeric suffix for UInt64 values.

source

Numeric suffix for UInt128 values.

source

Floating Point Numbers

Numeric suffix for Float16 values.

source

Numeric suffix for Float32 values.

source

Numeric suffix for Float64 values.

source

Complex Floating Point Numbers

Numeric suffix for Complex{Float16} values.

source

Numeric suffix for Complex{Float32} values.

source

Numeric suffix for Complex{Float64} values.

source