Skip to content

feat: implement essential numeric and logical builtin functions#27

Merged
schell merged 7 commits into
mainfrom
12-essential-numeric-and-logical-builtin-functions-priority-1
Dec 31, 2025
Merged

feat: implement essential numeric and logical builtin functions#27
schell merged 7 commits into
mainfrom
12-essential-numeric-and-logical-builtin-functions-priority-1

Conversation

@schell

@schell schell commented Dec 31, 2025

Copy link
Copy Markdown
Owner

Summary

Implements Issue #12 - Essential Numeric and Logical Builtin Functions (Priority 1)

Adds 13 WGSL builtin functions following the existing trait-per-function pattern.

Numeric Functions (10)

  • dot - Dot product for Vec{2,3,4}f/i/u
  • normalize - Unit vector for Vec{2,3,4}f
  • cross - Cross product for Vec3f only
  • clamp - Value clamping for f32/i32/u32 and all vector types
  • mix - Linear interpolation for f32 and Vec{2,3,4}f
  • floor - Floor for f32 and Vec{2,3,4}f
  • ceil - Ceiling for f32 and Vec{2,3,4}f
  • exp - Natural exponentiation (e^x) for f32 and Vec{2,3,4}f
  • exp2 - Base-2 exponentiation (2^x) for f32 and Vec{2,3,4}f
  • degrees - Radians to degrees for f32 and Vec{2,3,4}f

Logical Functions (3)

  • all - Returns true if all components are true (Vec{2,3,4}b)
  • any - Returns true if any component is true (Vec{2,3,4}b)
  • select - Conditional select for all scalar and vector types

Testing

  • Added 13 sanity tests for all new functions
  • All 39 tests pass
  • Clippy passes with no warnings

Closes #12

…#12)

Adds 13 WGSL builtin functions:

Numeric functions:
- dot: Dot product for Vec{2,3,4}f/i/u
- normalize: Unit vector for Vec{2,3,4}f
- cross: Cross product for Vec3f
- clamp: Value clamping for f32/i32/u32 and vectors
- mix: Linear interpolation for f32 and Vec{2,3,4}f
- floor: Floor for f32 and Vec{2,3,4}f
- ceil: Ceiling for f32 and Vec{2,3,4}f
- exp: Natural exponentiation for f32 and Vec{2,3,4}f
- exp2: Base-2 exponentiation for f32 and Vec{2,3,4}f
- degrees: Radians to degrees for f32 and Vec{2,3,4}f

Logical functions:
- all: Returns true if all components are true (Vec{2,3,4}b)
- any: Returns true if any component is true (Vec{2,3,4}b)
- select: Conditional select for all scalar and vector types

Closes #12
Copilot AI review requested due to automatic review settings December 31, 2025 01:43
@schell schell linked an issue Dec 31, 2025 that may be closed by this pull request
13 tasks

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 implements 13 essential numeric and logical builtin functions for WGSL, addressing Issue #12. The implementation adds dot product, vector normalization, cross product, clamping, linear interpolation, floor/ceiling operations, exponential functions, radians-to-degrees conversion, and logical operations (all, any, select).

Key Changes

  • Added 10 numeric functions: dot, normalize, cross, clamp, mix, floor, ceil, exp, exp2, and degrees
  • Added 3 logical functions: all, any, and select
  • Added 13 sanity tests covering basic functionality of all new functions

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
crates/wgsl-rs/src/std/numeric_builtin_functions.rs Implements 13 new builtin functions following the trait-per-function pattern, adds sanity tests, and updates documentation table to mark functions as implemented
SESSION.md Documents the implementation work including function list, type support matrix, and verification steps

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/wgsl-rs/src/std/numeric_builtin_functions.rs Outdated
Comment thread crates/wgsl-rs/src/std/numeric_builtin_functions.rs Outdated
Comment thread crates/wgsl-rs/src/std/numeric_builtin_functions.rs Outdated
The documentation incorrectly stated 'e^e' which was confusing since 'e'
was used for both the mathematical constant and the input variable.
Changed to 'e raised to the power of the input' for clarity.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/wgsl-rs/src/std/numeric_builtin_functions.rs Outdated
Comment thread crates/wgsl-rs/src/std/numeric_builtin_functions.rs Outdated
Comment thread crates/wgsl-rs/src/std/numeric_builtin_functions.rs Outdated
@schell schell merged commit c89117d into main Dec 31, 2025
4 checks passed
@schell schell deleted the 12-essential-numeric-and-logical-builtin-functions-priority-1 branch December 31, 2025 19:31
schell added a commit that referenced this pull request May 29, 2026
* feat: implement essential numeric and logical builtin functions (issue #12)

Adds 13 WGSL builtin functions:

Numeric functions:
- dot: Dot product for Vec{2,3,4}f/i/u
- normalize: Unit vector for Vec{2,3,4}f
- cross: Cross product for Vec3f
- clamp: Value clamping for f32/i32/u32 and vectors
- mix: Linear interpolation for f32 and Vec{2,3,4}f
- floor: Floor for f32 and Vec{2,3,4}f
- ceil: Ceiling for f32 and Vec{2,3,4}f
- exp: Natural exponentiation for f32 and Vec{2,3,4}f
- exp2: Base-2 exponentiation for f32 and Vec{2,3,4}f
- degrees: Radians to degrees for f32 and Vec{2,3,4}f

Logical functions:
- all: Returns true if all components are true (Vec{2,3,4}b)
- any: Returns true if any component is true (Vec{2,3,4}b)
- select: Conditional select for all scalar and vector types

Closes #12

* better select can use boolean vectors too

* better select can use boolean vectors too

* docs: fix exp function documentation to clarify e^x notation

The documentation incorrectly stated 'e^e' which was confusing since 'e'
was used for both the mathematical constant and the input variable.
Changed to 'e raised to the power of the input' for clarity.

* simplifications

* deleted SelectCondition

* pr fixup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Essential Numeric and Logical Builtin Functions (Priority 1)

2 participants