LogoLogo
Join The CommunityCommunity ResourcesLuafaq.orgLua Org
  • Welcome
  • Frequently Asked Questions (FAQ)
  • Legacy API
    • Test The API
    • Warning
    • Character
      • v1/wear
      • v1/remove
    • Games
      • v1/games/details
    • User
      • v1/user/request-data
      • v1/user/avatar
      • v1/user/get-by-username
      • v1/user/get-token
      • v1/user/verify-password
      • v1/user/login
      • v1/user/chat/send-message
      • v1/user/chat/chat-summary
      • v1/user/get-messages
      • v1/user/chat/chats
      • v1/user/friends
      • v1/user/friend
      • v1/user/search
    • Guild
      • v1/join
    • Asset
      • v1/sell
      • v1/take-offsale
      • v1/purchase
      • v1/purchase-reseller
      • v1/create
      • v1/get
  • OPEN CLOUD
    • READ ME
    • NPM Package
      • Introduction
      • Tutorials
        • Webhook Configuration
      • Bot Account
      • OpenCloudClient
      • WebAPICliet
        • Client
        • login
        • quit
        • Friends Endpoint
          • SendFriendRequest
          • GetFriends
        • User Endpoint
          • GetAvatar
          • GetPlayerByUsername
        • Guild Endpoint
          • JoinGuild
    • Open Cloud
    • Webhooks
    • Asset Types
    • Beautiful JSON Display
    • V2 API
      • Asset
        • Edit
      • Publish
        • Asset
        • World
      • Feed
        • reply
        • all/{page_cursor/{feed_cursor}
      • Cloud
        • oauth
          • create
        • git/{channel}
        • version
        • database
          • get
          • set
        • credentials
          • list
          • delete
          • create
        • bricklinks
          • list
          • delete
          • create
      • Webhook
        • delete
        • create
        • list
      • User
        • feed
          • send
        • search
        • register
        • login
        • username-available
        • email-available
        • phone-available
        • validate-beta-key
        • id
        • username
        • edit-setting
        • transparency-request
      • Auth
        • send-beta-key
        • get-active-sessions
        • terminate-session
        • get-token
        • session
        • is-authed
        • join-game
        • bot-login
      • Notifications
        • unread
        • all
        • erase
      • Worlds
        • /{universe}/{server}/server/metadata/update/{token}
        • /{universe}/shutdown/all/{token}
        • /{universe}/shutdown/server/{server}/{token}
        • /{universe}/join/server/{server_id}
        • /{universe}/join/random
        • /{universe}/join/user/{user_id}
        • /client/{join_key}
        • /create-universe/{ownerId}/{ownerType}
        • /create-world/{universeId}
        • /worldtree/{worldId}
  • Developer Guide
    • Empowering Responsible Gameplay: A Guide to ModerationService in BrickVerse
    • Empowering Game Creators: A Deep Dive into ENVService with Lua API in BrickVerse
    • Leveraging ENVService as an FFlag System
    • What's Authority?
    • Roblox Vs BrickVerse Classes
    • DRM - Digital Rights Management
  • BrickLua - Coding With Lua
    • Introduction
    • Learn Lua
      • Functions
      • Strings
      • Tables
      • Boolean
      • Conditional Structures
      • Opeartors
      • bit32
      • Numbers
    • Player Event
  • GAME API
    • API
      • Intro
      • math
      • debug
      • coroutine
      • Enum
        • UserInput
        • Humanoid
    • Classes
      • ServiceProvider
        • Enum
        • InteractionService
        • ENVService
        • Void
        • WorldstoreService
        • WorldSettings
        • DiscordRichPresence
        • ClientGui
        • AuthorityService
        • SharedStorage
        • WebService
        • RunService
        • NetworkService
        • AdService
        • UserInputService
        • Scene
        • ChatService
        • Lighting
        • SoundService
        • Players
        • ServerStorage
        • ScriptService
      • DataType
        • CFrame
        • Instance
        • Vector2
        • Vector3
        • Color
      • Dynamic
        • Dynamic3D
          • SpotLight
          • SpawnPart
          • Projection3D
          • PartMaterial
          • OmniLight
          • BasePart
          • InteractionPrompt
          • Page
          • DirectionalLight
          • Brick
          • BasePartConstraint
        • ScriptDynamic
          • ScriptModule
        • BaseUI
          • ScrollFrame
          • ImageButton
          • TextButton
          • ImageLabel
          • TextLabel
          • Frame
          • ViewportFrame
          • ScreenUI
  • Employment
    • List Of Administrators
Powered by GitBook
On this page
  • Signed and Unsigned
  • Notation
  • Operations
  • Number Classifications

Was this helpful?

Edit on GitHub
  1. BrickLua - Coding With Lua
  2. Learn Lua

Numbers

Previousbit32NextPlayer Event

Last updated 1 year ago

Was this helpful?

A number in Lua is a double precision floating point number (or just double). For instance:

  • 5

  • 9.12761656

  • -1927

In Lua, numbers can range from -1.7 × 10308 to 1.7 × 10308 (around 15 digits, positive or negative).

Signed and Unsigned

The sign of the number indicates whether it’s positive or negative. A signed number can be positive or negative, but an unsigned number cannot be negative. In Lua, -0 is distinct from 0.

Notation

Numbers are notated with the most significant digits first (big-endian). There are multiple ways to notate number literals in Lua:

  • — Write the digits of the number normally using digits 0–9 with a single optional decimal point, for example 7, 1.25, or -22.5.

  • — Write a decimal number followed by e or e+, then an integer to raise the decimal number to a power of 10. For instance, 12e3 is 12 × 10^3 (12,000).

  • — Begin the number with 0x followed by digits 0–9 or A–F (capitalization ignored). For example, 0xF is 15 and 0x3FC is 1020.

  • — Begin the number with 0b followed by 0s or 1s, for instance 0b1100 (12 in decimal format).

To aid in the readability of long numbers, underscores can be included anywhere within a number literal without changing the value, except at the beginning (in which case it would become an identifier). For example, 1_234_567 is the same as 1234567, both of which are equal to 1,234,567.

Operations

Number Classifications

In BrickLua, there is no technical difference between the following types of numbers. However, number classifications are used in documentation to indicate which kind of number is involved with an API member.

int

The int number type refers to a number without a fractional portion (integer) like 0, 60, or -42. Properties and functions that expect integers may automatically round or raise errors when provided with non-integers.

When working with integers in Lua, note the following:

  • The fractional portion of a number can be trimmed by rounding down with math.floor().

  • You can determine if a number is an integer by comparing math.floor(x) == x.

int64

The int64 number type refers to a signed 64-bit integer, a signed 64-bit integer is expected (-263 to 263 - 1).

float

Lua math and relational can be used on numbers to manipulate and compare them. Mathematical functions such as math.sqrt() and math.exp() can be found in the library and, for bitwise operations, the library has been back-ported.

To a number to the nearest integer (half up), use math.floor(x + 0.5).

The float number type refers to a . This type isn’t as precise as normal numbers, but the difference typically won’t matter.

Decimal (base-10)
Scientific notation
Hexadecimal (base-16)
Binary (base-2)
operators
math
bit32
round
single-precision (32-bit) floating point number