Skip to main content
Home

Built and signed on GitHub Actions

Works with
This package works with Node.js, Deno, Bun, BrowsersIt is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score100%
Publisheda year ago (1.0.0)

Primitive data types for representing specific numeric ranges

Primitive data types for representing specific numeric ranges and behaviors

This module provides classes for handling integers with 8-bit, 16-bit, and 32-bit ranges and a 32-bit floating-point number type

Each class ensures values stay within the specified range, supporting wrap-around for overflow, which simulates low-level data type constraints

Examples

Example 1

import { Int8, Int16, Int32, Float32 } from "@forest/primitives";
import { assertEquals } from "@std/assert";

const smallInt = new Int8(127);         // 8-bit integer
const mediumInt = new Int16(32767);     // 16-bit integer
const largeInt = new Int32(2147483647); // 32-bit integer
const floatVal = new Float32(3.14);     // 32-bit floating-point number

assertEquals(smallInt.valueOf(), 127);
assertEquals(mediumInt.valueOf(), 32767);
assertEquals(largeInt.valueOf(), 2147483647);
assertEquals(floatVal.valueOf(), 3.14);

const outOfRangeInt = new Int8(200); // Value goes out of 8-bit signed range
assertEquals(outOfRangeInt.valueOf(), -56); // Expected result due to overflow
Built and signed on
GitHub Actions

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@forest/primitives

Import symbol

import * as primitives from "@forest/primitives";
or

Import directly with a jsr specifier

import * as primitives from "jsr:@forest/primitives";

Add Package

pnpm i jsr:@forest/primitives
or (using pnpm 10.8 or older)
pnpm dlx jsr add @forest/primitives

Import symbol

import * as primitives from "@forest/primitives";

Add Package

yarn add jsr:@forest/primitives
or (using Yarn 4.8 or older)
yarn dlx jsr add @forest/primitives

Import symbol

import * as primitives from "@forest/primitives";

Add Package

vlt install jsr:@forest/primitives

Import symbol

import * as primitives from "@forest/primitives";

Add Package

npx jsr add @forest/primitives

Import symbol

import * as primitives from "@forest/primitives";

Add Package

bunx jsr add @forest/primitives

Import symbol

import * as primitives from "@forest/primitives";