-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created pylib.ts, added functions as built-ins to Python supporting B…
…igInt typing. (#1591) * Changed createContext, created pylib to support BigInt type in Python * Added pylib.ts for bigint-supported binary operations * Fixed typos in pylib and createContext * Removed obsolete defining Math library in PYTHON_1 * Fixed formatting to pass Prettier test * Fix format --------- Co-authored-by: Richard Dominick <[email protected]> Co-authored-by: Martin Henz <[email protected]>
- Loading branch information
1 parent
7db94b5
commit c4fc20d
Showing
2 changed files
with
254 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
import { Value } from '../types' | ||
|
||
export function __py_adder(x: Value, y: Value) { | ||
if (typeof x === typeof y) { | ||
return x + y | ||
} | ||
return Number(x) + Number(y) | ||
} | ||
|
||
export function __py_minuser(x: Value, y: Value) { | ||
if (typeof x === typeof y) { | ||
return x - y | ||
} | ||
return Number(x) - Number(y) | ||
} | ||
|
||
export function __py_multiplier(x: Value, y: Value) { | ||
if (typeof x === typeof y) { | ||
return x * y | ||
} | ||
return Number(x) * Number(y) | ||
} | ||
|
||
export function __py_divider(x: Value, y: Value) { | ||
return Number(x) / Number(y) | ||
} | ||
|
||
export function __py_modder(x: Value, y: Value) { | ||
if (typeof x === typeof y) { | ||
return x % y | ||
} | ||
return Number(x) % Number(y) | ||
} | ||
|
||
export function __py_powerer(x: Value, y: Value) { | ||
if (typeof x == 'bigint' && typeof y == 'bigint') { | ||
let res = BigInt(1) | ||
for (let i = 0; i < y; i++) { | ||
res = res * x | ||
} | ||
return res | ||
} | ||
return Math.pow(Number(x), Number(y)) | ||
} | ||
|
||
export function __py_floorer(x: Value, y: Value) { | ||
return Math.floor(Number(x) / Number(y)) | ||
} | ||
|
||
export function __py_unary_plus(x: Value) { | ||
if (typeof x == 'bigint') { | ||
return +Number(x) | ||
} | ||
return +x | ||
} | ||
|
||
export function math_abs(x: Value) { | ||
return Math.abs(Number(x)) | ||
} | ||
|
||
export function math_acos(x: Value) { | ||
return Math.acos(Number(x)) | ||
} | ||
|
||
export function math_acosh(x: Value) { | ||
return Math.acosh(Number(x)) | ||
} | ||
|
||
export function math_asin(x: Value) { | ||
return Math.asin(Number(x)) | ||
} | ||
|
||
export function math_asinh(x: Value) { | ||
return Math.asinh(Number(x)) | ||
} | ||
|
||
export function math_atan(x: Value) { | ||
return Math.atan(Number(x)) | ||
} | ||
|
||
export function math_atan2(y: Value, x: Value) { | ||
return Math.atan2(Number(y), Number(x)) | ||
} | ||
|
||
export function math_atanh(x: Value) { | ||
return Math.atanh(Number(x)) | ||
} | ||
|
||
export function math_cbrt(x: Value) { | ||
return Math.cbrt(Number(x)) | ||
} | ||
|
||
export function math_ceil(x: Value) { | ||
return Math.ceil(Number(x)) | ||
} | ||
|
||
export function math_clz32(x: Value) { | ||
return Math.clz32(Number(x)) | ||
} | ||
|
||
export function math_cos(x: Value) { | ||
return Math.cos(Number(x)) | ||
} | ||
|
||
export function math_cosh(x: Value) { | ||
return Math.cosh(Number(x)) | ||
} | ||
|
||
export function math_exp(x: Value) { | ||
return Math.exp(Number(x)) | ||
} | ||
|
||
export function math_expm1(x: Value) { | ||
return Math.expm1(Number(x)) | ||
} | ||
|
||
export function math_floor(x: Value) { | ||
return Math.floor(Number(x)) | ||
} | ||
|
||
export function math_fround(x: Value) { | ||
return Math.fround(Number(x)) | ||
} | ||
|
||
export function math_hypot(...elements: Value[]) { | ||
const coercedElements: number[] = elements.map(el => { | ||
return Number(el) | ||
}) | ||
return Math.hypot(...coercedElements) | ||
} | ||
|
||
export function math_imul(x: Value, y: Value) { | ||
return Math.imul(Number(x), Number(y)) | ||
} | ||
|
||
export function math_log(x: Value) { | ||
return Math.log(Number(x)) | ||
} | ||
|
||
export function math_log1p(x: Value) { | ||
return Math.log1p(Number(x)) | ||
} | ||
|
||
export function math_log2(x: Value) { | ||
return Math.log2(Number(x)) | ||
} | ||
|
||
export function math_log10(x: Value) { | ||
return Math.log10(Number(x)) | ||
} | ||
|
||
export function math_max(...elements: Value[]) { | ||
const coercedElements: number[] = elements.map(el => { | ||
return Number(el) | ||
}) | ||
return Math.max(...coercedElements) | ||
} | ||
|
||
export function math_min(...elements: Value[]) { | ||
const coercedElements: number[] = elements.map(el => { | ||
return Number(el) | ||
}) | ||
return Math.min(...coercedElements) | ||
} | ||
|
||
export function math_pow(x: Value, y: Value) { | ||
return Math.pow(Number(x), Number(y)) | ||
} | ||
|
||
export function math_random() { | ||
return Math.random() | ||
} | ||
|
||
export function math_round(x: Value) { | ||
return Math.round(Number(x)) | ||
} | ||
|
||
export function math_sign(x: Value) { | ||
return Math.sign(Number(x)) | ||
} | ||
|
||
export function math_sin(x: Value) { | ||
return Math.sin(Number(x)) | ||
} | ||
|
||
export function math_sinh(x: Value) { | ||
return Math.sinh(Number(x)) | ||
} | ||
|
||
export function math_sqrt(x: Value) { | ||
return Math.sqrt(Number(x)) | ||
} | ||
|
||
export function math_tan(x: Value) { | ||
return Math.tan(Number(x)) | ||
} | ||
|
||
export function math_tanh(x: Value) { | ||
return Math.tanh(Number(x)) | ||
} | ||
|
||
export function math_trunc(x: Value) { | ||
return Math.trunc(Number(x)) | ||
} |