Skip to content

Commit

Permalink
Remove is_number(), added is_float() and is_int() to Python (#1665)
Browse files Browse the repository at this point in the history
* Remove is_number(), add is_float() and is_int()

* Add is_float() and is_int()
  • Loading branch information
JJtan2002 authored Apr 10, 2024
1 parent 640b36c commit 5d5f1f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/createContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,8 @@ export const importBuiltins = (context: Context, externalBuiltIns: CustomBuiltIn
defineBuiltin(context, 'str(val)', (val: any) => stringify(val, 2, 80), 1)
defineBuiltin(context, 'error(str)', misc.error_message, 1)
defineBuiltin(context, 'prompt(str)', prompt)
defineBuiltin(context, 'is_number(val)', misc.is_number)
defineBuiltin(context, 'is_float(val)', pylib.is_float)
defineBuiltin(context, 'is_int(val)', pylib.is_int)
defineBuiltin(context, 'is_string(val)', misc.is_string)
defineBuiltin(context, 'is_function(val)', misc.is_function)
defineBuiltin(context, 'is_boolean(val)', misc.is_boolean)
Expand Down
8 changes: 8 additions & 0 deletions src/stdlib/pylib.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { Value } from '../types'

export function is_float(v: Value) {
return typeof v === 'number'
}

export function is_int(v: Value) {
return typeof v === 'bigint'
}

export function __py_adder(x: Value, y: Value) {
if (typeof x === typeof y) {
return x + y
Expand Down

0 comments on commit 5d5f1f3

Please sign in to comment.