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

成都建设局网站景德镇市建设局建设信用网站

成都建设局网站,景德镇市建设局建设信用网站,浙江大成建设集团有限公司网站,长宁哪里有做网站优化比较好jdk 取整数JDK 15 Early Access Build b18向Math和StrictMath类引入了新方法#xff0c;这些方法将在提供的值超出方法所支持的范围时抛出ArithmeticException #xff0c;而不会溢出。 这些方法为Java中的“绝对值”概念带来了Math.addExact #xff0c; Math.subtractExac… jdk 取整数 JDK 15 Early Access Build b18向Math和StrictMath类引入了新方法这些方法将在提供的值超出方法所支持的范围时抛出ArithmeticException 而不会溢出。 这些方法为Java中的“绝对值”概念带来了Math.addExact Math.subtractExact和Math.multiplyExact之类的方法带来的基本算术功能。 在JDK 15之前 Integer.MIN_VALUE和Long.MIN_VALUE使相应的方法Math.abs和StrictMath.abs返回相同的负数如MIN_VALUE可能的最大负数所表示。 此行为在Javadoc文档中针对受影响的方法进行了描述并通过以下所示的代码进行了演示 可在GitHub上找到 演示JDK之前的15种绝对值方法 /** * Demonstrates absExact methods added to {link Math} * and {link StrictMath} with JDK 15 Early Access Build b18 * (JDK-8241374: https://bugs.openjdk.java.net/browse/JDK-8241374 ). */ public class AbsoluteExactness { public void demonstrateMathAbsInteger( final int integer) { out.println( Math.abs( integer ): Math.abs(integer)); } public void longNumber) demonstrateMathAbsLong( final long longNumber) { out.println( Math.abs( longNumber L): Math.abs(longNumber)); } public void demonstrateStrictMathAbsInteger( final int integer) { out.println( StrictMath.abs( integer ): StrictMath.abs(integer)); } public void longNumber) demonstrateStrictMathAbsLong( final long longNumber) { out.println( StrictMath.abs( longNumber L): StrictMath.abs(longNumber)); } public static void main( final String[] arguments) { final AbsoluteExactness instance new AbsoluteExactness(); // Demonstrate pre-JDK 15 Math/StrictMath abs functions on minimum values. instance.demonstrateMathAbsInteger(Integer.MIN_VALUE 1 ); instance.demonstrateMathAbsInteger(Integer.MIN_VALUE); instance.demonstrateMathAbsLong(Long.MIN_VALUE 1 ); instance.demonstrateMathAbsLong(Long.MIN_VALUE); instance.demonstrateStrictMathAbsInteger(Integer.MIN_VALUE 1 ); instance.demonstrateStrictMathAbsInteger(Integer.MIN_VALUE); instance.demonstrateStrictMathAbsLong(Long.MIN_VALUE 1 ); instance.demonstrateStrictMathAbsLong(Long.MIN_VALUE); } } 执行以上代码后将写入以下输出 Math.abs(- 2147483647 ): 2147483647 Math.abs(- 2147483648 ): - 2147483648 Math.abs(-9223372036854775807L): 9223372036854775807 Math.abs(-9223372036854775808L): - 9223372036854775808 StrictMath.abs(- 2147483647 ): 2147483647 StrictMath.abs(- 2147483648 ): - 2147483648 StrictMath.abs(-9223372036854775807L): 9223372036854775807 StrictMath.abs(-9223372036854775808L): - 9223372036854775808 此输出表明int和long范围内的最大负允许值导致从Math和StrictMath上的适当abs方法返回相同的值。 JDK 15 Early Access Build b18引入了absExact方法这种方法在这种情况下抛出ArithmeticException而不是返回负值。 以下代码 在GitHub上也有 证明了这一点 演示JDK 15引入的绝对方法 public class AbsoluteExactness { public void demonstrateMathAbsExactInteger( final int integer) { try { out.println( Math.absExact( integer ): Math.absExact(integer)); } catch (ArithmeticException exception) { err.println( Math.absExact( integer ): exception); } } public void longNumber) demonstrateMathAbsExactLong( final long longNumber) { try { out.println( Math.absExact( longNumber L): Math.absExact(longNumber)); } catch (ArithmeticException exception) { err.println( Math.absExact( longNumber L): exception); } } public void demonstrateStrictMathAbsExactInteger( final int integer) { try { out.println( StrictMath.absExact( integer ): StrictMath.absExact(integer)); } catch (ArithmeticException exception) { err.println( StrictMath.absExact( integer ): exception); } } public void longNumber) demonstrateStrictMathAbsExactLong( final long longNumber) { try { out.println( StrictMath.absExact( longNumber L): StrictMath.absExact(longNumber)); } catch (ArithmeticException exception) { err.println( StrictMath.absExact( longNumber L): exception); } } public static void main( final String[] arguments) { final AbsoluteExactness instance new AbsoluteExactness(); // Demonstrate JDK 15-introduced Math/StrictMath absExact functions // on minimum values. instance.demonstrateMathAbsExactInteger(Integer.MIN_VALUE 1 ); instance.demonstrateMathAbsExactInteger(Integer.MIN_VALUE); instance.demonstrateMathAbsExactLong(Long.MIN_VALUE 1 ); instance.demonstrateMathAbsExactLong(Long.MIN_VALUE); instance.demonstrateStrictMathAbsExactInteger(Integer.MIN_VALUE 1 ); instance.demonstrateStrictMathAbsExactInteger(Integer.MIN_VALUE); instance.demonstrateStrictMathAbsExactLong(Long.MIN_VALUE 1 ); instance.demonstrateStrictMathAbsExactLong(Long.MIN_VALUE); } 接下来显示此代码的输出并演示将MIN_VALUE传递给absExact方法时引发的清除异常消息。 Math.absExact(- 2147483647 ): 2147483647 Math.absExact(- 2147483648 ): java.lang.ArithmeticException: Overflow to represent absolute value of Integer.MIN_VALUE Math.absExact(-9223372036854775807L): 9223372036854775807 Math.absExact(-9223372036854775808L): java.lang.ArithmeticException: Overflow to represent absolute value of Long.MIN_VALUE StrictMath.absExact(- 2147483647 ): 2147483647 StrictMath.absExact(- 2147483648 ):java.lang.ArithmeticException: Overflow to represent absolute value of Integer.MIN_VALUE StrictMath.absExact(-9223372036854775807L): 9223372036854775807 StrictMath.absExact(-9223372036854775808L): java.lang.ArithmeticException: Overflow to represent absolute value of Long.MIN_VALUE 我发现通常对于意外的边缘情况抛出异常要比返回“某物”更好这需要我阅读Javadoc来了解该情况是什么以及在该情况下返回了什么。 该异常使我们很明显地遇到了边缘情况而不是发现从绝对值函数调用返回的负数仅在某个时间以后才实现并且在代码中“下游”。 如果没有其他问题那么仅使用Math.absExact和StrictMath.absExact方法就可以向Java开发人员暗示在使用Java的数学库来计算绝对值时要考虑一些“非精确”的可能性并且这种实现可能导致阅读Javadoc找出那些不确切的情况。 翻译自: https://www.javacodegeeks.com/2020/05/exact-absolute-integral-numbers-in-jdk-15.htmljdk 取整数
http://www.pierceye.com/news/383001/

相关文章:

  • 网站培训视频宝安新闻
  • 上海外贸建站推广公司服务专业的网站建设公司
  • 网站上传不了wordpress女孩学电子商务专业好就业吗
  • 石家庄网站开发工程师招聘网蜘蛛互联网站建设
  • 企业网站营销策划衡水企业做网站费用
  • 邯郸网站建设渠道通化网站建设公司
  • 做vip电影网站黑龙江省中国建设银行网站首页
  • 长沙便宜网站建设在线印章生成器
  • 网站编辑的工作内容WordPress添加上传下载
  • 公司网站需求建设银行企业网站首页
  • 一般找素材都是做哪几个网站呢郑州seo外包阿亮
  • 广州个人网站建设公司jsp网站建设模板
  • 全国的网站建设网站建设肆金手指排名7
  • 做网站如何防止被抄袭17zwd一起做网站官网
  • 北京鲜花的网站建设做任务网站有哪些内容
  • 互联网营销网站建设印章在线生成
  • 厦门seo网站管理南宁广告网页设计人才招聘
  • 沂水住房与城乡建设局网站wordpress如何建立论坛
  • 贵州省文化旅游网站建设的必要性查网站流量的网址
  • 自己做的网站怎么传到空间啊平面设计技术培训机构
  • php 做网站xml地图回龙观手机网站开发服务
  • 四川建设工程网上合同备案网站如何重新打开wordpress
  • 免费个人网站模板下载qq邮箱企业邮箱注册
  • 泰兴市网站建设wp怎么打开wordpress
  • wordpress可以建哪些网站吗开发app需要多少人
  • 0基础学做网站什么做网站做个网站一般要多少钱啊
  • 外贸营销型网站建设多少钱wordpress付费浏览
  • 网站空间可以换吗进网站备案
  • 番禺建设网站开发软件工程专业介绍
  • 如何做网站定位网站建设报价新鸿儒