Practical overview
When it fits
Consider it when contract logic requires complex arithmetic and its fixed-point representation, approximation limits and revert conditions fit the calculation. Prefer `powu` for unsigned integer powers; assess the principal-branch behavior and exponent-related phase error before choosing general `pow`.
Who it is for
- Solidity developers building contracts that require complex-number calculations.
- Developers evaluating fixed-point mathematical operations for decentralized finance contracts.
Documented uses
- Represent complex values with fixed-point real and imaginary components.
- Perform arithmetic such as addition, multiplication, division and integer powers in a contract.
- Calculate magnitude, convert between Cartesian and polar forms, or use complex square-root, logarithm and exponential functions.
Requirements & limits
The repository is public and identifies the library as MIT licensed.
- The library depends on PRBMath’s SD59x18 type, so inputs and outputs use 18-decimal fixed-point scaling.
- Exact operations may revert when results or required intermediates overflow; division by zero has a library-specific error.
- Approximate operations have stated domain limits and error bounds. For example,
atan2has a maximum stated polynomial error of 0.00151 radians, and trigonometric functions document an angle range from 0 through 1e10 ra - The README’s representative gas figures use a 1,000-run optimizer and IR pipeline on the Prague EVM and may vary in a consuming contract.
- The project documents both Foundry dependency installation and npm installation with Solidity remappings.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Add the library to a Foundry project
Install the library and its PRBMath dependency, then configure the documented import remappings.
Before you start
- A Solidity project using Foundry
- PRBMath v4.2.0 as the documented dependency
Steps
Install both dependencies with the documented Foundry command, pinning PRBMath to v4.2.0.
Add the remappings
@prb/math/=lib/prb-math/andnum_complex_solidity/=lib/num-complex-solidity/.Import
SD59x18,sd,ComplexandComplexMathfrom the documented paths in a Solidity consumer.
Expected outcome
The project has the dependency paths needed to use ComplexMath in a consuming contract.
Guide limitations
- This setup does not establish that a consumer contract compiles or behaves correctly.
- Operations can revert on overflow, unsupported domains or division by zero, as applicable.
Install through npm and configure Solidity remappings
Set up the documented node_modules dependency paths for a Solidity consumer.
Before you start
- A project that resolves Solidity packages through
node_modules - npm
Steps
Install
num_complex_solidityand@prb/mathwith the documented npm command.Configure
@prb/math/=node_modules/@prb/math/andnum_complex_solidity/=node_modules/num_complex_solidity/remappings.Use the documented import paths for PRBMath and the complex-number library in the Solidity consumer.
Expected outcome
The project has the documented package locations and remappings for importing the library.
Guide limitations
- The README describes this as an installation path; it does not document a complete consumer build or deployment procedure.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 10 October 2026
- Original website title
- partylikeits1983/num-complex-solidity · Official homepage title · retained in its source language

