From 497b7df13b617ef2753d5581c5978106e4f2b307 Mon Sep 17 00:00:00 2001 From: gptsarthak Date: Sun, 16 Apr 2023 17:00:24 +0530 Subject: [PATCH] Improve performance of exp() and exp2() --- src/libasr/runtime/lfortran_intrinsics.c | 5 +++++ src/runtime/math.py | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/libasr/runtime/lfortran_intrinsics.c b/src/libasr/runtime/lfortran_intrinsics.c index 8f272a02be..2815cb715e 100644 --- a/src/libasr/runtime/lfortran_intrinsics.c +++ b/src/libasr/runtime/lfortran_intrinsics.c @@ -281,6 +281,11 @@ LFORTRAN_API double _lfortran_dexp(double x) return exp(x); } +LFORTRAN_API double _lfortran_dexp2(double x) +{ + return exp2(x); +} + LFORTRAN_API float_complex_t _lfortran_cexp(float_complex_t x) { return cexpf(x); diff --git a/src/runtime/math.py b/src/runtime/math.py index 587c727a02..7bfad62c86 100644 --- a/src/runtime/math.py +++ b/src/runtime/math.py @@ -463,13 +463,21 @@ def exp(x: f64) -> f64: """ Return `e` raised to the power `x`. """ - return e**x + return _lfortran_dexp(x) + +@ccall +def _lfortran_dexp(x: f64) -> f64: + pass def exp2(x: f64) -> f64: """ Return `2` raised to the power `x`. """ - return f64((2.0)**x) + return _lfortran_dexp2(x) + +@ccall +def _lfortran_dexp2(x: f64) -> f64: + pass def mod(a: i32, b: i32) -> i32: