Update Item Specifications
parent
ec8cd0aba6
commit
005f49e691
1 changed files with 6 additions and 6 deletions
|
@ -61,12 +61,12 @@ export const sqrt = onType(Number, math => {
|
|||
return Returns(Number, Math.sqrt)
|
||||
}
|
||||
const complex = math.complex.resolve(Number, Number)
|
||||
return Returns(Union(Number, Complex(Number)), a => {
|
||||
return Returns(
|
||||
Union(Number, Complex(Number)),
|
||||
a => n < 0 ? complex(0, Math.sqrt(-a)) : Math.sqrt(a)
|
||||
if (isNaN(a)) return NaN
|
||||
if (n >= 0) return Math.sqrt(a)
|
||||
return complex(0, Math.sqrt(-a)
|
||||
})
|
||||
}]
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
Note here that ideally the accesses to `math.config.predictable` and `math.types.Complex` in this factory mean that the resulting implementation of `sqrt` will depend on the `predictable` property of `math.config`, and so only be invalidated when that property changes, not on any change to `math.config`, just the way that the other possible implementation would only be invalidated if the implementation of `complex` on `Number, Number` were updated, but unaffected if the implementation of `complex` on `BigInt, BigInt` changed. Also note the convenience that for unary signatures, you can supply just a type; you don't have to put it in braces.
|
||||
|
@ -78,7 +78,7 @@ export const tau = onType(
|
|||
Number, 6.2831853,
|
||||
BigNumber, math => math.bignumber('6.28318530717958647692'),
|
||||
[], math => math.resolve('tau', [math.config.constants])
|
||||
]
|
||||
)
|
||||
```
|
||||
A few things to note in this example: now clients of the eventual bundle can use `math.resolve('tau', math.BigNumber)` to get the BigNumber value of tau regardless of the current type in the config.constants setting, the plain `math.tau` should resolve to the correct scalar entity, and the plain `math.tau` should be reset if either config.constants changes or if the setting of math.tau on the type config.constants changes.
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue