Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9d067ab

Browse files
committed
Optimization for 'n^2'
Squares are much more common than other exponentiations, and 'n*n' is much more efficient than 'pow'.
1 parent 2f4162b commit 9d067ab

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

llimits.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ typedef l_uint32 Instruction;
326326

327327
/* exponentiation */
328328
#if !defined(luai_numpow)
329-
#define luai_numpow(L,a,b) ((void)L, l_mathop(pow)(a,b))
329+
#define luai_numpow(L,a,b) \
330+
((void)L, (b == 2) ? (a)*(a) : l_mathop(pow)(a,b))
330331
#endif
331332

332333
/* the others are quite standard operations */

0 commit comments

Comments
 (0)