当前位置:网站首页>math.pow()函数用法[通俗易懂]
math.pow()函数用法[通俗易懂]
2022-08-01 14:06:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
Math.pow(底数,几次方) 如:int a=3; int b=3; int c=(int)Math.pow(a,b); 就是3的三次方是多少;
c最终为27;
基础用法:用math.pow()实现数组的交错求和
int ant=0;
a+=b[i]*math.pow(-1,ant); //实现b数组的交错求和并放在a中
结果a=b[0]+b[1]-b[2]+b[3]-b[4]….
可能导致错误的情况: 如果底数 x 为负数并且指数 y 不是整数,将会导致 domain error 错误。 如果底数 x 和指数 y 都是 0,可能会导致 domain error 错误,也可能没有;这跟库的实现有关。 如果底数 x 是 0,指数 y 是负数,可能会导致 domain error 或 pole error 错误,也可能没有;这跟库的实现有关。
如果返回值太大或者太小,将会导致 range error 错误。
——————————————————————————————
这里 int c=(int)Math.pow(a,b) 中添加了一个(int),这是强制类型转换(cast),
之所以要用是因为Math.pow(a,b) 的计算结果返回是double类型,double类型转换为int类型就需要用到。
我们可以看看如果不加(int) ,程序是会提示你去 Cast to ‘int’
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/126411.html原文链接:https://javaforall.cn
边栏推荐
- [深入研究4G/5G/6G专题-47]: 5G Link Adaption链路自适应-3-下行链路自适应DLLA-PDSCH信道
- A Beginner's Guide to Performance Testing
- 论文详读《基于改进 LeNet-5 模型的手写体中文识别》,未完待补充
- The problem that the column becomes indexed after pd groupby and the aggregation column has no column name
- 魔众文档管理系统 v5.0.0
- 性能优化——粒子优化笔记
- JMP Pro 16.0 software installation package download and installation tutorial
- Longkou united chemical registration: through 550 million revenue xiu-mei li control 92.5% stake
- Wovent Bio IPO: Annual revenue of 480 million pension fund is a shareholder
- 十九届浙大城院程序设计竞赛 F.Sum of Numerators(数学/找规律)
猜你喜欢
Gradle series - Gradle tests, Gradle life cycle, settings.gradle description, Gradle tasks (based on Groovy documentation 4.0.4) day2-3
fh511小风扇主控芯片 便携式小风扇专用8脚IC 三档小风扇升压芯片sop8
论文详读《基于改进 LeNet-5 模型的手写体中文识别》,未完待补充
「计算复杂性」理论奠基人Juris Hartmanis逝世,曾获93年图灵奖
响应式2022英文企业官网源码,感觉挺有创意的
openEuler 社区12位开发者荣获年度开源贡献之星
207.数组序号转换
ECCV 2022|R2L: 用数据蒸馏加速NeRF
使用open3d可视化3d人脸
【无标题】
随机推荐
安培龙IPO过会:年营收5亿 同创伟业与中移创新是股东
iframe tag attribute description detailed [easy to understand]
分布式中的远程调用
Qt实战案例(56)——利用QProcess实现应用程序重启功能
sql中常用到的正则表达
2022-07-25 网工进阶(二十一)BGP-路由反射器、联盟、聚合
龙口联合化学通过注册:年营收5.5亿 李秀梅控制92.5%股权
论文笔记All about Eve: Execute-Verify Replication for Multi-Core Servers
微服务原生案例搭建
牛客刷SQL--4
Longkou united chemical registration: through 550 million revenue xiu-mei li control 92.5% stake
【每日一题】952. 按公因数计算最大组件大小
【每日一题】592. 分数加减运算
Qt实战案例(55)——利用QDir删除选定文件目录下的空文件夹
易优压双驱挖掘机压路机器类网站源码 v1.5.8
Pytorch —— 分布式模型训练
D - Draw Your Cards(模拟)
The role of the final keyword final and basic types, reference types
大佬们,datax同步数据,同步过程中要新增一个uuid,请问column 怎么写pgsql,uu
沃文特生物IPO过会:年营收4.8亿 养老基金是股东