Skip to content

Add pow function to UFix64 and UFix128#4473

Open
turbolent wants to merge 3 commits intomasterfrom
bastian/fixed-point-pow
Open

Add pow function to UFix64 and UFix128#4473
turbolent wants to merge 3 commits intomasterfrom
bastian/fixed-point-pow

Conversation

@turbolent
Copy link
Copy Markdown
Member

@turbolent turbolent commented Apr 18, 2026

Work towards #1151

Description

Add pow function to UFix64 and UFix128 fixed-point types, backed by Pow methods in https://github.com/onflow/fixed-point:

  • UFix64.pow(_ exponent: Fix64): UFix64
  • UFix128.pow(_ exponent: Fix128): UFix128

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@turbolent turbolent self-assigned this Apr 18, 2026
@turbolent turbolent requested a review from SupunS as a code owner April 18, 2026 00:01
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 18, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 18, 2026

Benchstat comparison

  • Base branch: onflow:master
  • Base commit: e8fe69b
Results

old.txtnew.txt
time/opdelta
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ByteArrayTransfer-41.22µs ± 0%1.24µs ± 0%~(p=1.000 n=1+1)
ByteArrayValueToByteSlice-474.4ns ± 0%77.2ns ± 0%~(p=1.000 n=1+1)
ByteSliceToByteArrayValue-4879ns ± 0%979ns ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/compiler goos:linux goarch:amd64
CompileFungibleTokenTransferTransaction-4123µs ± 0%126µs ± 0%~(p=1.000 n=1+1)
CompileTime-436.8µs ± 0%36.4µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ContractFunctionInvocation-4374µs ± 0%372µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ContractImport-4209µs ± 0%223µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
EMVAddressTransfer-43.10µs ± 0%3.34µs ± 0%~(p=1.000 n=1+1)
Emit-44.29ms ± 0%4.43ms ± 0%~(p=1.000 n=1+1)
EnumTransfer-41.23µs ± 0%1.35µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ExportType/composite_type-4246ns ± 0%283ns ± 0%~(p=1.000 n=1+1)
ExportType/simple_type-473.6ns ± 0%74.9ns ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
FTTransfer-4147µs ± 0%149µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/sema goos:linux goarch:amd64
FlowTokenContract-4585µs ± 0%604µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ImperativeFib-422.1µs ± 0%21.9µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ImperativeFib-424.2µs ± 0%23.6µs ± 0%~(p=1.000 n=1+1)
ImperativeFibNewCompilerNewVM-449.6µs ± 0%47.7µs ± 0%~(p=1.000 n=1+1)
ImperativeFibNewVM-427.2µs ± 0%28.1µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
InterpretRecursionFib-42.24ms ± 0%2.28ms ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
InterpreterFTTransfer-4121µs ± 0%125µs ± 0%~(p=1.000 n=1+1)
InterpreterImperativeFib-423.4µs ± 0%21.8µs ± 0%~(p=1.000 n=1+1)
InterpreterNewStruct-463.1µs ± 0%63.7µs ± 0%~(p=1.000 n=1+1)
MethodCall/concrete_type_method_call-442.2µs ± 0%43.6µs ± 0%~(p=1.000 n=1+1)
MethodCall/interface_method_call-459.3µs ± 0%59.3µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
NewInterpreter/new_interpreter-4871ns ± 0%822ns ± 0%~(p=1.000 n=1+1)
NewInterpreter/new_sub-interpreter-4314ns ± 0%337ns ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
NewResource-4100µs ± 0%100µs ± 0%~(p=1.000 n=1+1)
NewStruct-443.9µs ± 0%44.1µs ± 0%~(p=1.000 n=1+1)
NewStructRaw-43.01µs ± 0%2.89µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/sema goos:linux goarch:amd64
QualifiedIdentifierCreation/One_level-42.04ns ± 0%2.05ns ± 0%~(p=1.000 n=1+1)
QualifiedIdentifierCreation/Three_levels-477.4ns ± 0%78.0ns ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
RecursionFib-41.56ms ± 0%1.51ms ± 0%~(p=1.000 n=1+1)
RuntimeFungibleTokenTransfer-4731µs ± 0%706µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
RuntimeFungibleTokenTransferInterpreter-4596µs ± 0%609µs ± 0%~(p=1.000 n=1+1)
RuntimeFungibleTokenTransferVM-4664µs ± 0%679µs ± 0%~(p=1.000 n=1+1)
RuntimeResourceDictionaryValues-42.58ms ± 0%2.72ms ± 0%~(p=1.000 n=1+1)
RuntimeResourceTracking-49.34ms ± 0%9.26ms ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-413.9µs ± 0%14.0µs ± 0%~(p=1.000 n=1+1)
RuntimeVMInvokeContractImperativeFib-439.7µs ± 0%41.4µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/sema goos:linux goarch:amd64
SuperTypeInference/arrays-4223ns ± 0%214ns ± 0%~(p=1.000 n=1+1)
SuperTypeInference/composites-483.7ns ± 0%88.1ns ± 0%~(p=1.000 n=1+1)
SuperTypeInference/integers-4295ns ± 0%301ns ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ValueIsSubtypeOfSemaType-457.6ns ± 0%57.2ns ± 0%~(p=1.000 n=1+1)
 
alloc/opdelta
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ByteArrayTransfer-41.06kB ± 0%1.06kB ± 0%~(p=1.000 n=1+1)
ByteArrayValueToByteSlice-432.0B ± 0%32.0B ± 0%~(all equal)
ByteSliceToByteArrayValue-4850B ± 0%859B ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/compiler goos:linux goarch:amd64
CompileFungibleTokenTransferTransaction-482.9kB ± 0%82.9kB ± 0%~(p=1.000 n=1+1)
CompileTime-416.9kB ± 0%16.9kB ± 0%~(all equal)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ContractFunctionInvocation-4144kB ± 0%144kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ContractImport-475.4kB ± 0%75.4kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
EMVAddressTransfer-42.45kB ± 0%2.45kB ± 0%~(p=1.000 n=1+1)
Emit-41.49MB ± 0%1.49MB ± 0%~(p=1.000 n=1+1)
EnumTransfer-4890B ± 0%893B ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ExportType/composite_type-4120B ± 0%120B ± 0%~(all equal)
ExportType/simple_type-40.00B 0.00B ~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
FTTransfer-443.7kB ± 0%43.7kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/sema goos:linux goarch:amd64
FlowTokenContract-4226kB ± 0%226kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ImperativeFib-48.30kB ± 0%8.30kB ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ImperativeFib-45.41kB ± 0%5.41kB ± 0%~(all equal)
ImperativeFibNewCompilerNewVM-425.8kB ± 0%25.8kB ± 0%~(all equal)
ImperativeFibNewVM-48.10kB ± 0%8.10kB ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
InterpretRecursionFib-41.19MB ± 0%1.19MB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
InterpreterFTTransfer-442.0kB ± 0%42.0kB ± 0%~(p=1.000 n=1+1)
InterpreterImperativeFib-48.29kB ± 0%8.29kB ± 0%~(all equal)
InterpreterNewStruct-424.9kB ± 0%24.8kB ± 0%~(p=1.000 n=1+1)
MethodCall/concrete_type_method_call-410.2kB ± 0%10.2kB ± 0%~(p=1.000 n=1+1)
MethodCall/interface_method_call-417.1kB ± 0%17.1kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
NewInterpreter/new_interpreter-4976B ± 0%976B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-4232B ± 0%232B ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
NewResource-444.0kB ± 0%44.0kB ± 0%~(p=1.000 n=1+1)
NewStruct-413.4kB ± 0%13.4kB ± 0%~(p=1.000 n=1+1)
NewStructRaw-41.75kB ± 0%1.71kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/sema goos:linux goarch:amd64
QualifiedIdentifierCreation/One_level-40.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-464.0B ± 0%64.0B ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
RecursionFib-4283kB ± 0%283kB ± 0%~(all equal)
RuntimeFungibleTokenTransfer-4241kB ± 0%242kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
RuntimeFungibleTokenTransferInterpreter-4165kB ± 0%165kB ± 0%~(p=1.000 n=1+1)
RuntimeFungibleTokenTransferVM-4188kB ± 0%188kB ± 0%~(p=1.000 n=1+1)
RuntimeResourceDictionaryValues-41.76MB ± 0%1.76MB ± 0%~(p=1.000 n=1+1)
RuntimeResourceTracking-46.96MB ± 0%6.96MB ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-48.08kB ± 0%8.07kB ± 0%~(p=1.000 n=1+1)
RuntimeVMInvokeContractImperativeFib-413.4kB ± 0%13.4kB ± 0%~(all equal)
pkg:github.com/onflow/cadence/sema goos:linux goarch:amd64
SuperTypeInference/arrays-472.0B ± 0%72.0B ± 0%~(all equal)
SuperTypeInference/composites-40.00B 0.00B ~(all equal)
SuperTypeInference/integers-40.00B 0.00B ~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ValueIsSubtypeOfSemaType-432.0B ± 0%32.0B ± 0%~(all equal)
 
allocs/opdelta
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ByteArrayTransfer-47.00 ± 0%7.00 ± 0%~(all equal)
ByteArrayValueToByteSlice-41.00 ± 0%1.00 ± 0%~(all equal)
ByteSliceToByteArrayValue-45.00 ± 0%5.00 ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/compiler goos:linux goarch:amd64
CompileFungibleTokenTransferTransaction-4576 ± 0%576 ± 0%~(all equal)
CompileTime-4209 ± 0%209 ± 0%~(all equal)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ContractFunctionInvocation-42.25k ± 0%2.25k ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ContractImport-41.29k ± 0%1.29k ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
EMVAddressTransfer-429.0 ± 0%29.0 ± 0%~(all equal)
Emit-440.0k ± 0%40.0k ± 0%~(all equal)
EnumTransfer-413.0 ± 0%13.0 ± 0%~(all equal)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ExportType/composite_type-43.00 ± 0%3.00 ± 0%~(all equal)
ExportType/simple_type-40.00 0.00 ~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
FTTransfer-41.40k ± 0%1.40k ± 0%~(all equal)
pkg:github.com/onflow/cadence/sema goos:linux goarch:amd64
FlowTokenContract-43.58k ± 0%3.58k ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ImperativeFib-4176 ± 0%176 ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ImperativeFib-4266 ± 0%266 ± 0%~(all equal)
ImperativeFibNewCompilerNewVM-4473 ± 0%473 ± 0%~(all equal)
ImperativeFibNewVM-4308 ± 0%308 ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
InterpretRecursionFib-417.7k ± 0%17.7k ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
InterpreterFTTransfer-4916 ± 0%916 ± 0%~(all equal)
InterpreterImperativeFib-4175 ± 0%175 ± 0%~(all equal)
InterpreterNewStruct-4418 ± 0%418 ± 0%~(all equal)
MethodCall/concrete_type_method_call-4354 ± 0%354 ± 0%~(all equal)
MethodCall/interface_method_call-4464 ± 0%464 ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
NewInterpreter/new_interpreter-415.0 ± 0%15.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-44.00 ± 0%4.00 ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
NewResource-4951 ± 0%951 ± 0%~(all equal)
NewStruct-4388 ± 0%388 ± 0%~(all equal)
NewStructRaw-430.0 ± 0%30.0 ± 0%~(all equal)
pkg:github.com/onflow/cadence/sema goos:linux goarch:amd64
QualifiedIdentifierCreation/One_level-40.00 0.00 ~(all equal)
QualifiedIdentifierCreation/Three_levels-42.00 ± 0%2.00 ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
RecursionFib-415.8k ± 0%15.8k ± 0%~(all equal)
RuntimeFungibleTokenTransfer-44.09k ± 0%4.09k ± 0%~(all equal)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
RuntimeFungibleTokenTransferInterpreter-43.08k ± 0%3.08k ± 0%~(all equal)
RuntimeFungibleTokenTransferVM-43.61k ± 0%3.61k ± 0%~(all equal)
RuntimeResourceDictionaryValues-436.7k ± 0%36.7k ± 0%~(all equal)
RuntimeResourceTracking-4129k ± 0%129k ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-4114 ± 0%114 ± 0%~(all equal)
RuntimeVMInvokeContractImperativeFib-4426 ± 0%426 ± 0%~(all equal)
pkg:github.com/onflow/cadence/sema goos:linux goarch:amd64
SuperTypeInference/arrays-43.00 ± 0%3.00 ± 0%~(all equal)
SuperTypeInference/composites-40.00 0.00 ~(all equal)
SuperTypeInference/integers-40.00 0.00 ~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ValueIsSubtypeOfSemaType-41.00 ± 0%1.00 ± 0%~(all equal)
 

@turbolent turbolent force-pushed the bastian/fixed-point-pow branch from 79cf240 to cade23a Compare April 18, 2026 00:17
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 18, 2026

Codecov Report

❌ Patch coverage is 94.31818% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
interpreter/value_number.go 76.19% 4 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Comment thread bbq/vm/builtin_globals.go
follow existing pattern already used by saturating arithmetic functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants