Skip to content

Conversation

@tedpatrick
Copy link
Contributor

This pull request adds support for the power operator (**) across all major numeric types in the SPy language, including both integer and floating-point types. It introduces the necessary operator implementations, updates the operator dispatch system, and provides comprehensive tests to ensure correct behavior for various type combinations and edge cases.

Power operator support for numeric types:

  • Implemented efficient power functions for i8, u8, i32, u32, and f64 in spy_operator$*_pow functions in spy/operator.h, handling both positive and negative exponents appropriately.
  • Added w_pow implementations for integer types (i8, u8, i32, u32) and w_f64_pow for floating-point types, enabling the VM to perform power operations natively. [1] [2]

Operator dispatch and registration:

  • Registered the ** operator for all relevant type pairs in the operator multimethod system, including mixed integer/float cases, ensuring correct dispatch for expressions like i32 ** i32, f64 ** i32, etc. [1] [2] [3] [4] [5] [6]
  • Added the ** operator to the main operator mapping, making it available for use in the language.
  • Implemented the generic w_POW handler in the VM, which dispatches to the correct implementation or type method as appropriate.

Testing:

  • Added a comprehensive test suite for the power operator, covering all supported types, edge cases (e.g., zero and negative exponents), mixed-type scenarios, and usage within complex expressions.

@Viriathus1
Copy link
Contributor

Hi @tedpatrick, just from a quick glance I noticed you didn't add the operator for the f32 type and also the custom is to add the operator unit tests into the following files test_int.py and test_float.py in that directory.

One other note is the inclusion of the guide to add operators doesn't quite fit the purpose of the docs section in my opinion. I'm sure @antocuni will confirm one or another for that one.

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.

2 participants