{"id":"hawakiki/luau-mathlib","name":"luau-mathlib","scope":"hawakiki","platform":"roblox","description":"JavaScript-style Math API for Roblox and Luau","version":"0.1.0","latest":"0.1.0","versions":["0.1.0"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"38b0cc117a0f7cddc61108ccb64ff995c6deabf5aac2d8d481bcbfacbd882552","likes":0,"downloads":0,"install":"forest install hawakiki/luau-mathlib","url":"https://forest.dev/p/roblox/hawakiki/luau-mathlib","files":"https://api.forest.dev/ai/package/roblox/hawakiki/luau-mathlib/files","readme":"# Luau Math LIB\r\n\r\nLuau Math LIB is a Roblox/Luau utility package that mirrors JavaScript-style `Math` APIs while staying easy to consume from Roblox Studio projects. The library exposes constants, wrappers around Luau's native `math` functions, and helper functions such as `cbrt`, `clz32`, `fround`, `hypot`, `imul`, `sign`, and `trunc`.\r\n\r\n## Features\r\n\r\n- Modular source layout: every function lives in its own ModuleScript under `module/src/functions`.\r\n- Shared type surface in `module/src/Types.luau` for strict Luau projects.\r\n- JavaScript-inspired constants: `E`, `LN2`, `LN10`, `LOG2E`, `LOG10E`, `PI`, `SQRT1_2`, and `SQRT2`.\r\n- Works with Rojo projects and Wally package workflows.\r\n\r\n## Installation\r\n\r\n### Option 1: Install with Wally\r\n\r\nAdd the package to your `wally.toml` dependencies:\r\n\r\n```toml\r\n[dependencies]\r\nLuauMathLib = \"hawakiki/luau-mathlib@0.1.0\"\r\n```\r\n\r\nThen install packages:\r\n\r\n```bash\r\nwally install\r\n```\r\n\r\nRequire the package from the generated `Packages` folder in your Roblox code.\r\n\r\n### Option 2: Use this repository with Rojo\r\n\r\nInstall the project tools listed in `rokit.toml` if you use Rokit:\r\n\r\n```bash\r\nrokit install\r\n```\r\n\r\nBuild the Roblox place file:\r\n\r\n```bash\r\nrojo build -o \"Luau_MathLIB.rbxlx\"\r\n```\r\n\r\nOr start a live Rojo server:\r\n\r\n```bash\r\nrojo serve\r\n```\r\n\r\nOpen the project in Roblox Studio and connect Rojo. The library is mounted at `ReplicatedStorage.LIB` by `dev.project.json`.\r\n\r\n## Usage Tutorial\r\n\r\n### 1. Require the library\r\n\r\nFrom a Script, LocalScript, or ModuleScript that can access `ReplicatedStorage`:\r\n\r\n```luau\r\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\r\nlocal Math = require(ReplicatedStorage.LIB)\r\n```\r\n\r\n### 2. Use constants\r\n\r\n```luau\r\nprint(Math.PI) -- 3.14159...\r\nprint(Math.SQRT2) -- square root of 2\r\n```\r\n\r\n### 3. Use direct math wrappers\r\n\r\n```luau\r\nlocal angle = Math.atan2(10, 5)\r\nlocal root = Math.sqrt(144)\r\nlocal power = Math.pow(2, 8)\r\n\r\nprint(angle, root, power)\r\n```\r\n\r\n### 4. Use helper functions missing from Luau's base `math` table\r\n\r\n```luau\r\nlocal distance = Math.hypot(3, 4, 12) -- 13\r\nlocal cubeRoot = Math.cbrt(-27) -- -3\r\nlocal direction = Math.sign(-100) -- -1\r\nlocal whole = Math.trunc(-12.75) -- -12\r\n\r\nprint(distance, cubeRoot, direction, whole)\r\n```\r\n\r\n### 5. Use strict Luau types\r\n\r\n```luau\r\nlocal Math = require(game.ReplicatedStorage.LIB)\r\n\r\ntype MathLibrary = typeof(Math)\r\n\r\nlocal function calculate(lib: MathLibrary, value: number): number\r\n\treturn lib.round(lib.sqrt(value))\r\nend\r\n\r\nprint(calculate(Math, 10))\r\n```\r\n\r\n## API Reference\r\n\r\n### Constants\r\n\r\n- `Math.E`\r\n- `Math.LN2`\r\n- `Math.LN10`\r\n- `Math.LOG2E`\r\n- `Math.LOG10E`\r\n- `Math.PI`\r\n- `Math.SQRT1_2`\r\n- `Math.SQRT2`\r\n\r\n### Functions\r\n\r\n- `Math.abs(n)`\r\n- `Math.acos(n)`\r\n- `Math.acosh(n)`\r\n- `Math.asin(n)`\r\n- `Math.asinh(n)`\r\n- `Math.atan(n)`\r\n- `Math.atan2(y, x)`\r\n- `Math.atanh(n)`\r\n- `Math.cbrt(n)`\r\n- `Math.ceil(n)`\r\n- `Math.clz32(n)`\r\n- `Math.cos(n)`\r\n- `Math.cosh(n)`\r\n- `Math.exp(n)`\r\n- `Math.expm1(n)`\r\n- `Math.f16round(n)`\r\n- `Math.floor(n)`\r\n- `Math.fround(n)`\r\n- `Math.hypot(...numbers)`\r\n- `Math.imul(left, right)`\r\n- `Math.log(n)`\r\n- `Math.log10(n)`\r\n- `Math.log1p(n)`\r\n- `Math.log2(n)`\r\n- `Math.max(...numbers)`\r\n- `Math.min(...numbers)`\r\n- `Math.pow(base, exponent)`\r\n- `Math.random()`\r\n- `Math.round(n)`\r\n- `Math.sign(n)`\r\n- `Math.sin(n)`\r\n- `Math.sinh(n)`\r\n- `Math.sqrt(n)`\r\n- `Math.tan(n)`\r\n- `Math.tanh(n)`\r\n- `Math.trunc(n)`\r\n\r\n## Running Tests\r\n\r\nThis project includes TestEZ specs in `test/init.spec.luau`. Run them from Roblox Studio or your preferred Roblox test runner after syncing the project with Rojo.\r\n\r\n## Project Layout\r\n\r\n```text\r\nmodule/\r\n  init.luau              # public API aggregator\r\n  src/\r\n    Types.luau           # exported strict Luau type surface\r\n    constants.luau       # math constants\r\n    functions/           # one ModuleScript per function\r\ntest/\r\n  init.spec.luau         # TestEZ coverage\r\n```\r\n\r\n## License\r\n\r\nThis project is available under the license in `LICENSE`.\r\n","readmeTruncated":false}