Commit ef520b21

ef520b211151Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified

Description

Add Math module method dispatch

Support all standard Math module functions (sin, cos, tan, asin, acos, atan, atan2, sinh, cosh, tanh, asinh, acosh, atanh, exp, log, log2, log10, sqrt, cbrt, hypot, ldexp, erf, erfc) in both analyze.c (return TY_FLOAT) and codegen.c (emit direct C math.h calls). Two-argument forms (log with base, atan2, hypot, ldexp) also handled.

Co-Authored-By: Claude Sonnet 4.6 [email protected]

Details

Commit
ef520b211151
Parent
7ed9f18ce32d

src/analyze.cmodifiedView file

@@ -422,6 +422,17 @@
422422 !strcmp(name, "sqrt"))
423423 return TY_INT;
424424 if (rty && !strcmp(rty, "ConstantReadNode") &&
425+ nt_str(nt, recv, "name") && !strcmp(nt_str(nt, recv, "name"), "Math") &&
426+ (!strcmp(name, "sin") || !strcmp(name, "cos") || !strcmp(name, "tan") ||
427+ !strcmp(name, "asin") || !strcmp(name, "acos") || !strcmp(name, "atan") ||
428+ !strcmp(name, "atan2") || !strcmp(name, "sinh") || !strcmp(name, "cosh") ||
429+ !strcmp(name, "tanh") || !strcmp(name, "asinh") || !strcmp(name, "acosh") ||
430+ !strcmp(name, "atanh") || !strcmp(name, "exp") || !strcmp(name, "log") ||
431+ !strcmp(name, "log2") || !strcmp(name, "log10") || !strcmp(name, "sqrt") ||
432+ !strcmp(name, "cbrt") || !strcmp(name, "hypot") || !strcmp(name, "frexp") ||
433+ !strcmp(name, "ldexp") || !strcmp(name, "erf") || !strcmp(name, "erfc")))
434+ return TY_FLOAT;
435+ if (rty && !strcmp(rty, "ConstantReadNode") &&
425436 nt_str(nt, recv, "name") && !strcmp(nt_str(nt, recv, "name"), "JSON") &&
426437 (!strcmp(name, "generate") || !strcmp(name, "dump")))
427438 return TY_STRING;