当前位置:网站首页>Number - number (Lua)
Number - number (Lua)
2022-07-07 19:14:00 【Just be interesting】
The number - number
stay Lua 5.3 The previous version ,number There is only one numerical form , Double precision floating point type . from Lua 5.3 After version ,Lua Of number Data types introduce shaping , Thus, there are two numerical representations , One is 64 position integer integer and Double precision floating point float.
-- As follows
a = 1 --integer
b = 1.0 --float
c = 1e4 --float
When the numerical constant is decimal or Index time ,number I'll take it as float, The rest are integers
Arithmetic operations
number Because of the distinction between integer and floating point , Therefore, we should pay attention to distinguish the differences in arithmetic operations .
The operator | describe |
---|---|
+ | Add |
- | Subtraction |
* | Multiplication |
/ | division , Keep decimal places |
% | Remainder |
^ | Power |
- | Minus sign |
//(Lua5.3 Only after that ) | division , Don't keep decimal places ( Whether it's an integer or a floating point number ) |
+ Add Integers are added into integers , In addition, floating point numbers
- Subtraction Integers are subtracted into integers , In addition, floating point numbers
* Multiplication Multiply integers into integers , In addition, floating point numbers
\ division ( Keep decimal places ), Whether it's an integer or a floating point number , The results are all floating-point numbers
^ Power , Whether it's an integer or a floating point number , The result is a floating-point number
\\ division ( Don't keep decimal places ), Divide an integer by an integer , The rest are floating point numbers
Math library
- Judgment type
math.type
: Judge number The type is integer still float (Lua 5.3)
- integer
math.floor
: Rounding down
math.ceil
: Rounding up
math.modf
: Round to zero , Returns two values , One is an integer , One is a decimal ( The fractional part )
a, b = 1.5, -1.5
print(math.floor(a), math.floor(b)) --1 -2
print(math.ceil(a), math.ceil(b)) -- 2 -1
print(math.modf(a)) -- 1 0.5
print(math.modf(b)) -- -1 -0.5
math.maxinteger
andmath.mininteger
Namely Maximum integer and Minimum integer , If the integer exceeds the expression ( Value overflow ), There will be a loop .Generally, it will not overflow , But we still need to pay attention to .
边栏推荐
- SlashData开发者工具榜首等你而定!!!
- Micro service remote debug, nocalhost + rainbow micro service development second bullet
- How to estimate the value of "not selling pens" Chenguang?
- POJ 1182 :食物链(并查集)[通俗易懂]
- First time in China! The language AI strength of this Chinese enterprise is recognized as No.2 in the world! Second only to Google
- 50亿,福建又诞生一只母基金
- 完整的电商系统
- Redis
- AI写首诗
- Antisamy: a solution against XSS attack tutorial
猜你喜欢
In 2021, the national average salary was released. Have you reached the standard?
How to choose the appropriate automated testing tools?
Save the memory of the model! Meta & UC Berkeley proposed memvit. The modeling time support is 30 times longer than the existing model, and the calculation amount is only increased by 4.5%
Reinforcement learning - learning notes 8 | Q-learning
抢占周杰伦
Charles+drony的APP抓包
5billion, another master fund was born in Fujian
I feel cheated. Wechat tests the function of "size number" internally, and two wechat can be registered with the same mobile number
Desci: is decentralized science the new trend of Web3.0?
PV静态创建和动态创建
随机推荐
GSAP animation library
Interview vipshop internship testing post, Tiktok internship testing post [true submission]
Recommend free online SMS receiving platform in 2022 (domestic and foreign)
Hongmeng smart home [1.0]
Redis publishing and subscription
Will low code help enterprises' digital transformation make programmers unemployed?
完整的电商系统
Charles+drony的APP抓包
Basic operation of chain binary tree (implemented in C language)
POJ 1182 :食物链(并查集)[通俗易懂]
Tapdata 的 2.0 版 ,开源的 Live Data Platform 现已发布
虚拟数字人里的生意经
Where does brain hole come from? New research from the University of California: creative people's neural connections will "take shortcuts"
2022.07.05
CVPR 2022 - learning non target knowledge for semantic segmentation of small samples
Do you know all four common cache modes?
Will domestic software testing be biased
Zhong Xuegao wants to remain innocent in the world
ES6笔记一
Kirk borne's selection of learning resources this week [click the title to download directly]