久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

        <bdo id='e2UIf'></bdo><ul id='e2UIf'></ul>
    1. <i id='e2UIf'><tr id='e2UIf'><dt id='e2UIf'><q id='e2UIf'><span id='e2UIf'><b id='e2UIf'><form id='e2UIf'><ins id='e2UIf'></ins><ul id='e2UIf'></ul><sub id='e2UIf'></sub></form><legend id='e2UIf'></legend><bdo id='e2UIf'><pre id='e2UIf'><center id='e2UIf'></center></pre></bdo></b><th id='e2UIf'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='e2UIf'><tfoot id='e2UIf'></tfoot><dl id='e2UIf'><fieldset id='e2UIf'></fieldset></dl></div>

        <legend id='e2UIf'><style id='e2UIf'><dir id='e2UIf'><q id='e2UIf'></q></dir></style></legend>
      1. <tfoot id='e2UIf'></tfoot>

        <small id='e2UIf'></small><noframes id='e2UIf'>

        如何檢測 32 位 int 上的整數(shù)溢出?

        How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數(shù)溢出?)
          <bdo id='YC3iA'></bdo><ul id='YC3iA'></ul>
        • <legend id='YC3iA'><style id='YC3iA'><dir id='YC3iA'><q id='YC3iA'></q></dir></style></legend>
              1. <small id='YC3iA'></small><noframes id='YC3iA'>

                <i id='YC3iA'><tr id='YC3iA'><dt id='YC3iA'><q id='YC3iA'><span id='YC3iA'><b id='YC3iA'><form id='YC3iA'><ins id='YC3iA'></ins><ul id='YC3iA'></ul><sub id='YC3iA'></sub></form><legend id='YC3iA'></legend><bdo id='YC3iA'><pre id='YC3iA'><center id='YC3iA'></center></pre></bdo></b><th id='YC3iA'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='YC3iA'><tfoot id='YC3iA'></tfoot><dl id='YC3iA'><fieldset id='YC3iA'></fieldset></dl></div>
                  <tbody id='YC3iA'></tbody>

                  <tfoot id='YC3iA'></tfoot>
                • 本文介紹了如何檢測 32 位 int 上的整數(shù)溢出?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我知道這樣的話題被問了好幾次,但我的問題是關于完整的 32 位 int 的溢出.例如:

                  I know such topic was asked several times, but my question is about overflow on full 32 bits of int. For example:

                    11111111111111111111111111111111 +
                    00000000000000000000000000000001 =
                    00000000000000000000000000000000   //overflow!
                  

                  我發(fā)現(xiàn) topic 有類似的問題,但是算法并不完美.

                  I found topic with similar question about this, however the algorithm is not perfect.

                    11111111111111111111111111111111 +
                    00000000000000000000000000000000 =
                    00000000000000000000000000000000  //overflow!
                  

                  有沒有什么簡單、快速、安全的檢查方法?

                  Is there any simple, fast, safer way to check this ?

                  推薦答案

                  Math.addExact 溢出時拋出異常

                  從 Java 8 開始,數(shù)學類:

                  Math.addExact throws exception on overflow

                  Since Java 8 there is a set of methods in the Math class:

                  • toIntExact(long)
                  • addExact(int,int)
                  • subtractExact(int,int)
                  • multiplyExact(int,int)

                  ……以及長期版本.

                  這些方法中的每一個都會拋出 ArithmeticException 如果發(fā)生溢出.否則,如果它在范圍內(nèi),它們會返回正確的結果.

                  Each of these methods throws ArithmeticException if overflow happens. Otherwise they return the proper result if it fits within the range.

                  加法示例:

                  int x = 2_000_000_000;
                  int y = 1_000_000_000;
                  try {
                      int result = Math.addExact(x, y);
                      System.out.println("The proper result is " + result);
                  } catch(ArithmeticException e) {
                      System.out.println("Sorry, " + e);
                  }
                  

                  查看此在 IdeOne.com 上實時運行的代碼.

                  對不起,java.lang.ArithmeticException:整數(shù)溢出

                  Sorry, java.lang.ArithmeticException: integer overflow

                  這篇關于如何檢測 32 位 int 上的整數(shù)溢出?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數(shù)轉(zhuǎn)換為整數(shù)?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內(nèi)創(chuàng)建一個隨機打亂數(shù)字的 int 數(shù)組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠?qū)?0xff000000 存儲為 int?)
                  Unexpected result in long/int division(意外結果導致長/整數(shù)除法)
                        <bdo id='zR0NF'></bdo><ul id='zR0NF'></ul>
                        1. <tfoot id='zR0NF'></tfoot>
                          <i id='zR0NF'><tr id='zR0NF'><dt id='zR0NF'><q id='zR0NF'><span id='zR0NF'><b id='zR0NF'><form id='zR0NF'><ins id='zR0NF'></ins><ul id='zR0NF'></ul><sub id='zR0NF'></sub></form><legend id='zR0NF'></legend><bdo id='zR0NF'><pre id='zR0NF'><center id='zR0NF'></center></pre></bdo></b><th id='zR0NF'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='zR0NF'><tfoot id='zR0NF'></tfoot><dl id='zR0NF'><fieldset id='zR0NF'></fieldset></dl></div>
                            <tbody id='zR0NF'></tbody>

                        2. <legend id='zR0NF'><style id='zR0NF'><dir id='zR0NF'><q id='zR0NF'></q></dir></style></legend>
                          • <small id='zR0NF'></small><noframes id='zR0NF'>

                            主站蜘蛛池模板: av在线播放网| 日本不卡一区二区三区在线观看 | 久久精品国产精品青草 | 久久这里有精品 | 久久综合伊人 | 国产区在线 | 免费观看黄网站 | 日本淫视频 | 91精品国产91 | 精品av久久久久电影 | 在线观看av网站永久 | 日韩在线视频观看 | 国产美女在线观看 | 久婷婷 | 国产精品欧美一区二区三区不卡 | 成人午夜视频在线观看 | 色欧美片视频在线观看 | 精品一区二区av | 免费人成在线观看网站 | 国产精品美女久久久久久不卡 | 狠狠干天天干 | 国产精品久久国产精品 | 久久男人 | 91秦先生艺校小琴 | 欧美日韩在线观看一区 | 蜜桃精品视频在线 | 国产精品看片 | 日韩亚洲欧美一区 | 91精品一区 | 狠狠操狠狠干 | 国产精品高潮呻吟久久av黑人 | 久久99精品国产麻豆婷婷 | 国产精品久久久久久久久久久久久久 | 欧美激情精品久久久久久免费 | 日韩精品 电影一区 亚洲 | 在线欧美亚洲 | 美女视频一区二区三区 | 天天综合永久 | 我要看一级片 | 第一福利社区1024 | 国产一级在线 |