当前位置:网站首页>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.maxintegerandmath.minintegerNamely 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 .
边栏推荐
- Version 2.0 of tapdata, the open source live data platform, has been released
- [Base64 notes] [suggestions collection]
- Zhong Xuegao wants to remain innocent in the world
- In the first half of 2022, I found 10 books that have been passed around by my circle of friends
- How much does it cost to develop a small program mall?
- 【MIME笔记】
- 线程池中的线程工厂
- AI写首诗
- Redis集群与扩展
- Reject policy of thread pool
猜你喜欢

微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹

50亿,福建又诞生一只母基金

Antisamy: a solution against XSS attack tutorial

二叉树的基本概念和性质

Standard ACL and extended ACL

Basic concepts and properties of binary tree

Review of network attack and defense
![Kirk borne's selection of learning resources this week [click the title to download directly]](/img/df/98aa3edf0a70b870684963d52e7c72.png)
Kirk borne's selection of learning resources this week [click the title to download directly]

Redis cluster and expansion

Former richest man, addicted to farming
随机推荐
【软件测试】从企业版BOSS直聘,看求职简历,你没被面上是有原因的
2022.07.04
PTA 1101 B是A的多少倍
【MIME笔记】
Sports Federation: resume offline sports events in a safe and orderly manner, and strive to do everything possible for domestic events
2022.07.02
POJ 1182 :食物链(并查集)[通俗易懂]
Reuse of data validation framework Apache bval
coming! Gaussdb (for Cassandra) new features appear
The moveposition function of rigidbody2d of unity2d solves the problem of people or screen jitter when moving
ip netns 命令(备忘)
Realize payment function in applet
Numpy——2.数组的形状
企业展厅设计中常用的三种多媒体技术形式
PTA 1102 teaching Super Champion volume
嵌入式面试题(算法部分)
Draw squares with Obama (Lua)
[software test] from the direct employment of the boss of the enterprise version, looking at the resume, there is a reason why you are not covered
Creative changes brought about by the yuan universe
Interview vipshop internship testing post, Tiktok internship testing post [true submission]