Skip to content

vacp2p/nim-intops

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

intops

intops is a Nim library with ready-to-use core primitives for CPU-sized integers.

The following operations are implemented:

  • addition
  • subtraction
  • multiplication

Addition and subtraction are available in the following flavors:

  • overflowing
  • carrying/borrowing
  • saturating

Multiplication is represented with its widening flavor.

All operations can be used during runtime and compile time. Runtime operations use C intrinsics, whereas compile-time operations are implemented in pure Nim.

Both unsigned and signed integers are supported.

API Docs

API Docs

Usage

Operations are available in the top-level intops module:

import intops

let (res, carryOut) = carryingAdd(12, 34, false)

If you want to get specifically a runtime or a compile-time version, import intops/pure or intops/native:

import intops/native

let (res, carryOut) = carryingAdd(12, 34, false)

And if you want to go even deeper and call the underlying intrinsic, import intops/intrinsics:

import intops/intrinsics

var res: uint64

let didOverflow = overflowingAdd(12, 34, res)

Running the tests

$ nimble test

Building the docs

$ nimble docs

About

intops is a Nim library with ready-to-use core primitives for CPU-sized integers.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages