Skip to content

jishnub/OddEvenIntegers.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OddEvenIntegers

CI codecov pkgeval

This package provides the types Odd and Even that may wrap an integer. Using these types, the result of isodd and iseven may be evaluated at compile time.

julia> Odd(3)
3

julia> Even(4)
4

julia> @code_typed isodd(Odd(3))
CodeInfo(
1return true
) => Bool

julia> @code_typed iseven(Even(4))
CodeInfo(
1return true
) => Bool

This package interfaces with HalfIntegers, so that the half of an Odd or an Even may access the half-integer methods, some of which may be evaluated at compile time. The canonical way to construct and use such a type is:

julia> using OddEvenIntegers, HalfIntegers

julia> x = half(Odd(3))
3/2

julia> @code_typed isinteger(x)
CodeInfo(
1return false
) => Bool

julia> x + 1
5/2

julia> @code_typed isinteger(x + 1)
CodeInfo(
1return false
) => Bool