当前位置: 首页 > news >正文

linux中常用的数值计算

 

001、 expr

[root@localhost test]# expr 3 + 5
8
[root@localhost test]# expr 3 - 5
-2
[root@localhost test]# expr 3 * 5
15
[root@localhost test]# expr 3 / 5      ## 支持加减乘除
0
[root@localhost test]# expr 3 / 5.3    ## 不支持浮点运算
expr: non-integer argument
[root@localhost test]# expr 5 / 3
1
[root@localhost test]# expr 8 / 3      ## 直接截断
2

image

 

002、echo + bc

[root@localhost test]# echo "5 + 3" | bc
8
[root@localhost test]# echo "5 - 3" | bc
2
[root@localhost test]# echo "5 * 3" | bc
15
[root@localhost test]# echo "5 / 3" | bc
1
[root@localhost test]# echo "scale = 3; 5 / 3" | bc          ## 支持浮点运算
1.666
[root@localhost test]# echo "scale = 5; 5 / 3" | bc
1.66666

image

 

 

http://www.sczhlp.com/news/699.html

相关文章:

  • 【问题】--Macbook相关问题
  • 软工作业day27
  • 2025.7.28 闲话:CF678E Another Sith Tournament 倒序状压 DP 的一点想法
  • 基础知识
  • java学习(大道至简读后感)
  • js基础第一天
  • 春训#1题解
  • 垃圾话1
  • 2025/7/28 总结
  • 7.27 周总结
  • 存贮电解液配方的二进制格式与解析它的010 Editor的模板
  • 读《大道至简——软件工程实践者的思想》有感
  • 动态规划
  • Wireshark入门指南:网络流量分析利器
  • 量子计算先驱David Schuster的二十年探索之路
  • SpringBoot中使用TOTP实现MFA(多因素认证) - Tom
  • 上拉电阻和下拉电阻
  • 蓝桥杯2024省赛A组题解
  • 春训#2题解
  • 国内AI编码工具哪家强CodeBuddy+通义灵码+Trae
  • js基础第二天
  • [PaperReading] Stable Video Diffusion: Scaling Latent Video Diffusion Models to Large Datasets
  • 蓝桥杯2025省赛A组游记题解
  • 7.28 闲话
  • FM2023利兹联崛起之路#1
  • 暑训#1补题
  • 07.08 论文精读 人像线稿生成模型
  • 7/28
  • 【LeetCode 141】算法:环形链表
  • 暑训#3补题