← Back to Lua Course | Chapter 2: Variables & Types | Lesson 4 of 7

Numbers का परिचय

Lua 5.3 में दो तरह के numbers हैं, whole-number integers और decimal floats, और यह इन्हें आपके लिए mix करता है।

In this page:

  1. Numbers

Numbers

Lua 5.3 में number type की integer और float subtypes हैं। Integers default से 64-bit हैं, और एक decimal point या exponent वाली value एक float है। Operations इन्हें automatically mix करते हैं, और math.type बताता है कि एक value की कौन-सी subtype है।

Note: "integer" या "float" check करने के लिए math.type(x) इस्तेमाल करें, क्योंकि type(x) सिर्फ "number" कहता है।

उदाहरण: Numbers

lua
print(10, 10.0, 1e2)
print(math.type(10), math.type(10.0), math.type("10"))
print(3 == 3.0)
print(math.maxinteger)
print(math.maxinteger + 1 == math.mininteger)

-- Output:
-- 10	10.0	100.0
-- integer	float	nil
-- true
-- 9223372036854775807
-- true
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह मान लेना कि सारे numbers floats हैं जैसा Lua 5.2 में होता था
  2. यह उम्मीद करना कि 3 और 3.0 same print होंगे
  3. यह उम्मीद करना कि integer overflow एक error raise करेगा
चैप्टर सारांश
  • Integer और float subtypes हैं
  • एक decimal point एक float बनाता है
  • math.type subtype reveal करता है
  • Overflow पर Integers wrap around करते हैं
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.