当前位置:网站首页>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 .
边栏推荐
- Three forms of multimedia technology commonly used in enterprise exhibition hall design
- Seize Jay Chou
- 来了!GaussDB(for Cassandra)新特性亮相
- 微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
- In the first half of 2022, I found 10 books that have been passed around by my circle of friends
- Reuse of data validation framework Apache bval
- 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%
- 基于图像和激光的多模态点云融合与视觉定位
- 直播预约通道开启!解锁音视频应用快速上线的秘诀
- First time in China! The language AI strength of this Chinese enterprise is recognized as No.2 in the world! Second only to Google
猜你喜欢
Nat address translation
DeSci:去中心化科学是Web3.0的新趋势?
Seize Jay Chou
App capture of charles+drony
In 2021, the national average salary was released. Have you reached the standard?
二叉树的基本概念和性质
Three forms of multimedia technology commonly used in enterprise exhibition hall design
[Tawang methodology] Tawang 3W consumption strategy - U & a research method
Antisamy: a solution against XSS attack tutorial
Complete e-commerce system
随机推荐
SD_ DATA_ SEND_ SHIFT_ REGISTER
PV静态创建和动态创建
【软件测试】从企业版BOSS直聘,看求职简历,你没被面上是有原因的
Static routing configuration
Redis的发布与订阅
初识缓存以及ehcache初体验「建议收藏」
testing and SQA_ Dynamic white box test [easy to understand]
基于图像和激光的多模态点云融合与视觉定位
LeetCode 497(C#)
2022.07.05
Reuse of data validation framework Apache bval
Cadre de validation des données Apache bval réutilisé
Big Ben (Lua)
Mathematical analysis_ Notes_ Chapter 11: Fourier series
Multimodal point cloud fusion and visual location based on image and laser
手把手教姐姐写消息队列
數據驗證框架 Apache BVal 再使用
IP netns command (memo)
Embedded interview questions (algorithm part)
SlashData开发者工具榜首等你而定!!!