Skip to content

Conversation

@nberlette
Copy link
Owner

  • chore: move trig/const/rand tests to src dir
  • refactor(ieee754): abstract out common parts of float16/32/64 modules
  • refactor(float16): use ieee754 abstractions for float16
  • feat(float16): add float16/constants submodule
  • feat(float16): add float16/guards submodule
  • refactor(float32): use ieee754 abstractions for float32 ops
  • feat(float32): add float32/constants submodule
  • feat(float32): add float32/guards submodule

@nberlette nberlette added documentation Improvements or additions to documentation enhancement New feature or request labels Jul 19, 2025
Copilot AI review requested due to automatic review settings July 19, 2025 15:02
@nberlette nberlette added documentation Improvements or additions to documentation enhancement New feature or request labels Jul 19, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the IEEE-754 floating-point implementation by extracting common functionality into a shared abstraction layer. The changes consolidate duplicate code between float16 and float32 modules while adding new constants and type guard submodules.

  • Introduces a shared IEEE-754 abstraction module to eliminate code duplication
  • Adds constants and guards submodules for both float16 and float32 formats
  • Moves test files from root to src directory for better organization

Reviewed Changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
src/random.test.ts Updates import path to relative reference
src/internal/ieee754.ts New shared IEEE-754 encoding/decoding abstraction
src/float32/round.ts Minor comment formatting improvement
src/float32/mod.ts Adds exports for new constants and guards submodules
src/float32/guards.ts New type guard functions for float32 validation
src/float32/encode.ts Refactored to use shared IEEE-754 abstraction
src/float32/decode.ts Refactored to use shared IEEE-754 abstraction
src/float32/constants.ts New constants module for float32 format specifications
src/float16/mod.ts Adds exports for new constants and guards submodules
src/float16/guards.ts New type guard functions for float16 validation
src/float16/encode.ts Refactored to use shared IEEE-754 abstraction
src/float16/decode.ts Refactored to use shared IEEE-754 abstraction
src/float16/constants.ts New constants module for float16 format specifications
src/constants.test.ts Updates import path to relative reference

@@ -0,0 +1,227 @@
// src/float/common.ts
Copy link

Copilot AI Jul 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment references an incorrect file path. It should reference 'src/internal/ieee754.ts' to match the actual file location.

Suggested change
// src/float/common.ts
// src/internal/ieee754.ts

Copilot uses AI. Check for mistakes.
nan: 0x7FFF8000000000000000000000000000n,
positive_infinity: 0x7FFF0000000000000000000000000000n,
negative_infinity: 0xFFFF0000000000000000000000000000n,
negative_zero: 0x8000000000000000n,
Copy link

Copilot AI Jul 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The negative_zero value for float128 appears to be incorrect. It should be 0x80000000000000000000000000000000n (32 hex digits) to match the 128-bit format, not 0x8000000000000000n (16 hex digits) which is for 64-bit.

Suggested change
negative_zero: 0x8000000000000000n,
negative_zero: 0x80000000000000000000000000000000n,

Copilot uses AI. Check for mistakes.
*/

/**
* The number of bits used for the exponent in the IEEE-754 half-precision
Copy link

Copilot AI Jul 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment incorrectly refers to 'half-precision' when describing float32 constants. It should refer to 'single-precision' instead.

Suggested change
* The number of bits used for the exponent in the IEEE-754 half-precision
* The number of bits used for the exponent in the IEEE-754 single-precision

Copilot uses AI. Check for mistakes.
export const FLOAT32_EXPONENT_BITS = 8;

/**
* The number of bits used for the mantissa in the IEEE-754 half-precision
Copy link

Copilot AI Jul 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment incorrectly refers to 'half-precision' when describing float32 constants. It should refer to 'single-precision' instead.

Suggested change
* The number of bits used for the mantissa in the IEEE-754 half-precision
* The number of bits used for the mantissa in the IEEE-754 single-precision

Copilot uses AI. Check for mistakes.
export const FLOAT32_MANTISSA_BITS = 23;

/**
* The exponent bias used in the IEEE-754 half-precision (or "binary32") format.
Copy link

Copilot AI Jul 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment incorrectly refers to 'half-precision' when describing float32 constants. It should refer to 'single-precision' instead.

Suggested change
* The exponent bias used in the IEEE-754 half-precision (or "binary32") format.
* The exponent bias used in the IEEE-754 single-precision (or "binary32") format.

Copilot uses AI. Check for mistakes.
export const FLOAT32_EXPONENT_BIAS = 127;

/**
* Well-known bit pattern representing `NaN` in the IEEE-754 half-precision (or
Copy link

Copilot AI Jul 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment incorrectly refers to 'half-precision' when describing float32 constants. It should refer to 'single-precision' instead.

Suggested change
* Well-known bit pattern representing `NaN` in the IEEE-754 half-precision (or
* Well-known bit pattern representing `NaN` in the IEEE-754 single-precision (or

Copilot uses AI. Check for mistakes.

/**
* Well-known bit pattern representing `+Infinity` (positive infinity) in the
* IEEE-754 half-precision (or "binary32") format.
Copy link

Copilot AI Jul 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment incorrectly refers to 'half-precision' when describing float32 constants. It should refer to 'single-precision' instead.

Suggested change
* IEEE-754 half-precision (or "binary32") format.
* IEEE-754 single-precision (or "binary32") format.

Copilot uses AI. Check for mistakes.

/**
* Well-known bit pattern representing `-Infinity` (negative infinity) in the
* IEEE-754 half-precision (or "binary32") format.
Copy link

Copilot AI Jul 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment incorrectly refers to 'half-precision' when describing float32 constants. It should refer to 'single-precision' instead.

Suggested change
* IEEE-754 half-precision (or "binary32") format.
* IEEE-754 single-precision (or "binary32") format.

Copilot uses AI. Check for mistakes.

/**
* Well-known bit pattern representing `-0` (negative zero) in the IEEE-754
* half-precision (or "binary32") format.
Copy link

Copilot AI Jul 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment incorrectly refers to 'half-precision' when describing float32 constants. It should refer to 'single-precision' instead.

Suggested change
* half-precision (or "binary32") format.
* single-precision (or "binary32") format.

Copilot uses AI. Check for mistakes.

/**
* Well-known bit pattern representing `+0` (positive zero) in the IEEE-754
* half-precision (or "binary32") format.
Copy link

Copilot AI Jul 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment incorrectly refers to 'half-precision' when describing float32 constants. It should refer to 'single-precision' instead.

Suggested change
* half-precision (or "binary32") format.
* single-precision (or "binary32") format.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants