Arithmetic और Comparison Operators
Lua में सामान्य maths operators हैं, साथ ही floor division और एक power operator।
In this page:
Arithmetic और Comparison Operators
Lua +, -, *, /, %, power के लिए ^, और floor division के लिए // देता है। / और ^ operators हमेशा floats देते हैं, जबकि // और % integers देते हैं जब दोनों operands integers हों। Comparisons ==, ~=, <, <=, > और >= इस्तेमाल करती हैं, और ध्यान दें कि not-equal ~= लिखा जाता है।
Note:
Lua में modulo divisor का sign लेता है, इसलिए -7 % 3 2 है।
उदाहरण: Arithmetic and comparison operators
print(7 / 2, 7 // 2, 7 % 3)
print(-7 // 2, -7 % 3)
print(2 ^ 10, 6 / 3)
print(7.5 // 2)
print(1 ~= 2, 1 == 1.0)
-- Output:
-- 3.5 3 1
-- -4 2
-- 1024.0 2.0
-- 3.0
-- true true
Login to try C/C++/Java/PHP code in the editor
आम गलतियां
- not equal के लिए != लिखना
- यह उम्मीद करना कि 7 / 2 3 होगा
- यह उम्मीद करना कि एक negative modulo result negative होगा
चैप्टर सारांश
- / हमेशा एक float देता है
- // floor division है
- ^ power तक raise करता है
- Not equal ~= है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: