Aller au contenu principal

Int

A tagged type to represent integer values

API

Motivation

There is no int in ES only number. Nevertheless, there is a notion of Safe Integer which represent an integer value in the range -2^53 to (2^53)-1, without any precision loss. Int is a Tag type that helps to validate at compile time that the value is a "safe integer".

Usage

import { Int } from '@w5s/core'

const one = Int(1);
const two = Int(2);
const three = Int['+'](one, two); // 3

Coding Guide

astuce

Prefer Int for type safety except when performance are critical

  • Int functions are designed to perform integer operations in a type safe way and represent explicitly all possible errors (parsing errors, division by zero, etc)
  • Int functions will never have better performance than inline regular number operation

FAQ