HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to LuaVariablesNumbers & MathStringsTablesConditions (if)Loops (for / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables
🔢 Numbers & Math
Arithmetic ( + - * / % ^ )math.sqrt / math.floor
✍️ String
📋 Table
🔁 Condition & Loop
🧩 Function
Lua›REFERENCE›Numbers & Math
🔢

Numbers & Math

Arithmetic and the math library.

CommandDescription
Arithmetic ( + - * / % ^ )Four basic operations, modulo, and exponentiation.
math.sqrt / math.floorMath functions.

Arithmetic ( + - * / % ^ )

Try it yourself →

Four basic operations, modulo, and exponentiation.

Syntax

a + b, a % b, a ^ b

Description

^ is the exponentiation operator (result is a float). // is floor division (Lua 5.3+).

Example

print(7 % 2)
print(2 ^ 10)
print(7 // 2)

Expected output

1
1024.0
3

When to use?

Calculations.

Common mistakes

  • ⚠️ ^ result is a float: 2^10 → 1024.0. Use math.floor or // for an integer.

math.sqrt / math.floor

Try it yourself →

Math functions.

Syntax

math.sqrt(x)

Description

math library: sqrt for square root, floor/ceil for rounding, max/min, random.

Example

print(math.sqrt(144))
print(math.floor(4.7))

Expected output

12.0
4

When to use?

Geometry, rounding.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code