首页 / JAVA / java-round函数源码
java-round函数源码
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java-round函数源码,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1230字,纯文字阅读大概需要2分钟。
内容图文
![java-round函数源码](/upload/InfoBanner/zyjiaocheng/1222/5df128d3fc6648bc9b21035f87e5769b.jpg)
看不懂,改天研究?如果记得的话
public static long round(double a) { long longBits = Double.doubleToRawLongBits(a); long biasedExp = (longBits & DoubleConsts.EXP_BIT_MASK) >> (DoubleConsts.SIGNIFICAND_WIDTH - 1); long shift = (DoubleConsts.SIGNIFICAND_WIDTH - 2 + DoubleConsts.EXP_BIAS) - biasedExp; if ((shift & -64) == 0) { // shift >= 0 && shift < 64 // a is a finite number such that pow(2,-64) <= ulp(a) < 1 long r = ((longBits & DoubleConsts.SIGNIF_BIT_MASK) | (DoubleConsts.SIGNIF_BIT_MASK + 1)); if (longBits < 0) { r = -r; } // In the comments below each Java expression evaluates to the value // the corresponding mathematical expression: // (r) evaluates to a / ulp(a) // (r >> shift) evaluates to floor(a * 2) // ((r >> shift) + 1) evaluates to floor((a + 1/2) * 2) // (((r >> shift) + 1) >> 1) evaluates to floor(a + 1/2) return ((r >> shift) + 1) >> 1; } else { // a is either // - a finite number with abs(a) < exp(2,DoubleConsts.SIGNIFICAND_WIDTH-64) < 1/2 // - a finite number with ulp(a) >= 1 and hence a is a mathematical integer // - an infinity or NaN return (long) a; } }
原文:https://www.cnblogs.com/zhizhiyin/p/8491135.html
内容总结
以上是互联网集市为您收集整理的java-round函数源码全部内容,希望文章能够帮你解决java-round函数源码所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。