-
Notifications
You must be signed in to change notification settings - Fork 30
Workaround for Math variadic functions #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
f111fd7
41fc71e
3910add
8f64689
2219eba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,50 @@ | ||
// Generated by ReScript, PLEASE EDIT WITH CARE | ||
|
||
import * as Caml_splice_call from "rescript/lib/es6/caml_splice_call.js"; | ||
|
||
var Constants = {}; | ||
|
||
var Int = {}; | ||
function minMany(arr) { | ||
if (arr.length !== 0) { | ||
return Caml_splice_call.spliceApply(Math.min, [arr]); | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
function maxMany(arr) { | ||
if (arr.length !== 0) { | ||
return Caml_splice_call.spliceApply(Math.max, [arr]); | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
var Int = { | ||
minMany: minMany, | ||
maxMany: maxMany | ||
}; | ||
|
||
function minMany$1(arr) { | ||
if (arr.length !== 0) { | ||
return Caml_splice_call.spliceApply(Math.min, [arr]); | ||
} else { | ||
return 0.0; | ||
} | ||
} | ||
|
||
function maxMany$1(arr) { | ||
if (arr.length !== 0) { | ||
return Caml_splice_call.spliceApply(Math.max, [arr]); | ||
} else { | ||
return 0.0; | ||
} | ||
} | ||
|
||
export { | ||
Constants , | ||
Int , | ||
minMany$1 as minMany, | ||
maxMany$1 as maxMany, | ||
} | ||
/* No side effect */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,19 @@ module Int = { | |
@val external clz32: int => int = "Math.clz32" | ||
@val external imul: (int, int) => int = "Math.imul" | ||
@val external min: (int, int) => int = "Math.min" | ||
@variadic @val external minMany: array<int> => int = "Math.min" | ||
@variadic @val external _minMany: array<int> => int = "Math.min" | ||
let minMany = arr => | ||
switch arr { | ||
| [] => 0 | ||
| arr => _minMany(arr) | ||
} | ||
@val external max: (int, int) => int = "Math.max" | ||
@variadic @val external maxMany: array<int> => int = "Math.max" | ||
@variadic @val external _maxMany: array<int> => int = "Math.max" | ||
let maxMany = arr => | ||
switch arr { | ||
| [] => 0 | ||
| arr => _maxMany(arr) | ||
} | ||
@val external pow: (int, ~exp: int) => int = "Math.pow" | ||
@val external sign: int => int = "Math.sign" | ||
} | ||
|
@@ -44,9 +54,19 @@ module Int = { | |
@val external log10: float => float = "Math.log10" | ||
@val external log2: float => float = "Math.log2" | ||
@val external min: (float, float) => float = "Math.min" | ||
@variadic @val external minMany: array<float> => float = "Math.min" | ||
@variadic @val external _minMany: array<float> => float = "Math.min" | ||
let minMany = arr => | ||
switch arr { | ||
| [] => 0.0 | ||
| arr => _minMany(arr) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure the These are also edge cases that are very unlikely to occur in practice, since variadic calls require syntactic arrays there's little chance of it happening by accident. I'd suggest the aim of this is restricted to just making the types sound. |
||
@val external max: (float, float) => float = "Math.max" | ||
@variadic @val external maxMany: array<float> => float = "Math.max" | ||
@variadic @val external _maxMany: array<float> => float = "Math.max" | ||
let maxMany = arr => | ||
switch arr { | ||
| [] => 0.0 | ||
| arr => _maxMany(arr) | ||
} | ||
@val external pow: (float, ~exp: float) => float = "Math.pow" | ||
@val external random: unit => float = "Math.random" | ||
@val external round: float => float = "Math.round" | ||
|
Uh oh!
There was an error while loading. Please reload this page.