Compare commits
2 Commits
fbec410c42
...
22f114d7f9
Author | SHA1 | Date | |
---|---|---|---|
22f114d7f9 | |||
9aec1bca17 |
10
src/generic/all.ts
Normal file
10
src/generic/all.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { ForType } from '../core/Dispatcher.js'
|
||||
import { GenericReturn } from './type.js'
|
||||
import * as generic from './arithmetic.js'
|
||||
|
||||
export { generic }
|
||||
|
||||
declare module "../core/Dispatcher" {
|
||||
interface ReturnTypes<Params>
|
||||
extends ForType<'numbers', GenericReturn<Params>> { }
|
||||
}
|
17
src/generic/arithmetic.ts
Normal file
17
src/generic/arithmetic.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { ConservativeUnary, Dependency, ImpType, Signature } from "../core/Dispatcher";
|
||||
|
||||
declare module "./type" {
|
||||
interface GenericReturn<Params> {
|
||||
// Jos: not sure how to define this or why it is needed
|
||||
square: Signature<Params, [T], T>
|
||||
// square: ConservativeUnary<Params, T>
|
||||
// square: Params extends [infer R]
|
||||
// ? R extends number ? UnderlyingReal<R> : never
|
||||
// : never
|
||||
}
|
||||
}
|
||||
|
||||
export const square =
|
||||
<T>(dep: Dependency<'multiply', [T, T]>):
|
||||
ImpType<'square', [T]> =>
|
||||
z => dep.multiply(z, z)
|
3
src/generic/type.ts
Normal file
3
src/generic/type.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export interface GenericReturn<Params> {
|
||||
|
||||
}
|
@ -1,27 +1,34 @@
|
||||
import {configDependency} from '../core/Config.js'
|
||||
import {Signature, ImpType} from '../core/Dispatcher.js'
|
||||
import { configDependency } from '../core/Config.js'
|
||||
import { Signature, ImpType, Dependency } from '../core/Dispatcher.js'
|
||||
|
||||
const DBL_EPSILON = Number.EPSILON || 2.2204460492503130808472633361816E-16
|
||||
|
||||
declare module "./type" {
|
||||
interface NumbersReturn<Params> {
|
||||
equal: Signature<Params, [number, number], boolean>
|
||||
unequal: Signature<Params, [number, number], boolean>
|
||||
}
|
||||
}
|
||||
|
||||
export const equal =
|
||||
(dep: configDependency): ImpType<'equal', [number, number]> =>
|
||||
(x, y) => {
|
||||
const eps = dep.config.epsilon
|
||||
if (eps === null || eps === undefined) return x === y
|
||||
if (x === y) return true
|
||||
if (isNaN(x) || isNaN(y)) return false
|
||||
(x, y) => {
|
||||
const eps = dep.config.epsilon
|
||||
if (eps === null || eps === undefined) return x === y
|
||||
if (x === y) return true
|
||||
if (isNaN(x) || isNaN(y)) return false
|
||||
|
||||
if (isFinite(x) && isFinite(y)) {
|
||||
const diff = Math.abs(x - y)
|
||||
if (diff < DBL_EPSILON) return true
|
||||
return diff <= Math.max(Math.abs(x), Math.abs(y)) * eps
|
||||
if (isFinite(x) && isFinite(y)) {
|
||||
const diff = Math.abs(x - y)
|
||||
if (diff < DBL_EPSILON) return true
|
||||
return diff <= Math.max(Math.abs(x), Math.abs(y)) * eps
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
return false
|
||||
export const unequal = (dep: Dependency<'equal', [number, number]>):
|
||||
ImpType<'unequal', [number, number]> =>
|
||||
(x, y) => {
|
||||
return !dep.equal(x, y)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user