-
-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: everything #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
nberlette
commented
Jul 19, 2025
- 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
There was a problem hiding this 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 | |||
Copilot
AI
Jul 19, 2025
There was a problem hiding this comment.
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.
| // src/float/common.ts | |
| // src/internal/ieee754.ts |
| nan: 0x7FFF8000000000000000000000000000n, | ||
| positive_infinity: 0x7FFF0000000000000000000000000000n, | ||
| negative_infinity: 0xFFFF0000000000000000000000000000n, | ||
| negative_zero: 0x8000000000000000n, |
Copilot
AI
Jul 19, 2025
There was a problem hiding this comment.
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.
| negative_zero: 0x8000000000000000n, | |
| negative_zero: 0x80000000000000000000000000000000n, |
| */ | ||
|
|
||
| /** | ||
| * The number of bits used for the exponent in the IEEE-754 half-precision |
Copilot
AI
Jul 19, 2025
There was a problem hiding this comment.
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.
| * 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 |
| export const FLOAT32_EXPONENT_BITS = 8; | ||
|
|
||
| /** | ||
| * The number of bits used for the mantissa in the IEEE-754 half-precision |
Copilot
AI
Jul 19, 2025
There was a problem hiding this comment.
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.
| * 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 |
| export const FLOAT32_MANTISSA_BITS = 23; | ||
|
|
||
| /** | ||
| * The exponent bias used in the IEEE-754 half-precision (or "binary32") format. |
Copilot
AI
Jul 19, 2025
There was a problem hiding this comment.
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.
| * 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. |
| export const FLOAT32_EXPONENT_BIAS = 127; | ||
|
|
||
| /** | ||
| * Well-known bit pattern representing `NaN` in the IEEE-754 half-precision (or |
Copilot
AI
Jul 19, 2025
There was a problem hiding this comment.
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.
| * 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 |
|
|
||
| /** | ||
| * Well-known bit pattern representing `+Infinity` (positive infinity) in the | ||
| * IEEE-754 half-precision (or "binary32") format. |
Copilot
AI
Jul 19, 2025
There was a problem hiding this comment.
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.
| * IEEE-754 half-precision (or "binary32") format. | |
| * IEEE-754 single-precision (or "binary32") format. |
|
|
||
| /** | ||
| * Well-known bit pattern representing `-Infinity` (negative infinity) in the | ||
| * IEEE-754 half-precision (or "binary32") format. |
Copilot
AI
Jul 19, 2025
There was a problem hiding this comment.
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.
| * IEEE-754 half-precision (or "binary32") format. | |
| * IEEE-754 single-precision (or "binary32") format. |
|
|
||
| /** | ||
| * Well-known bit pattern representing `-0` (negative zero) in the IEEE-754 | ||
| * half-precision (or "binary32") format. |
Copilot
AI
Jul 19, 2025
There was a problem hiding this comment.
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.
| * half-precision (or "binary32") format. | |
| * single-precision (or "binary32") format. |
|
|
||
| /** | ||
| * Well-known bit pattern representing `+0` (positive zero) in the IEEE-754 | ||
| * half-precision (or "binary32") format. |
Copilot
AI
Jul 19, 2025
There was a problem hiding this comment.
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.
| * half-precision (or "binary32") format. | |
| * single-precision (or "binary32") format. |