30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import Specifications from './type'
|
|
import configDependency from '../core/Config'
|
|
/// <reference path="../complex/type.ts">
|
|
|
|
declare module 'Dispatcher' {
|
|
namespace Specifications {
|
|
namespace NumberSpecifications {
|
|
export const add = (a: number, b: number) => a + b
|
|
export const unaryMinus = (a: number) => -a
|
|
export const subtract = (a: number, b: number) => a - b
|
|
export const multiply = (a: number, b: number) => a * b
|
|
export const divide = (a: number, b: number) => a / b
|
|
export const sqrt =
|
|
(dep: configDependency
|
|
& ImplementationDependency<'complex', [number,number]>) => {
|
|
if (dep.config.predictable || !dep.complex) {
|
|
return (a: number) => isNaN(n) ? NaN : Math.sqrt(n)
|
|
}
|
|
return (a: number) => {
|
|
if (isNaN(n)) return NaN
|
|
if (n >= 0) return Math.sqrt(n)
|
|
return dep.complex(0, Math.sqrt(unaryMinus(n)))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export {Specifications}
|