pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    1. <small id='QAdct'></small><noframes id='QAdct'>

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

        1.0 是 std::generate_canonical 的有效輸出嗎?

        Is 1.0 a valid output from std::generate_canonical?(1.0 是 std::generate_canonical 的有效輸出嗎?)

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

      2. <legend id='UdB43'><style id='UdB43'><dir id='UdB43'><q id='UdB43'></q></dir></style></legend>

            <bdo id='UdB43'></bdo><ul id='UdB43'></ul>
            • <tfoot id='UdB43'></tfoot>

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

                    <tbody id='UdB43'></tbody>
                2. 本文介紹了1.0 是 std::generate_canonical 的有效輸出嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我一直認為隨機數會介于 0 和 1 之間,沒有 1,即它們是來自半開區間 [0,1) 的數字.std::generate_canonical 的 cppreference.com 上的文檔 證實了這一點.

                  I always thought random numbers would lie between zero and one, without 1, i.e. they are numbers from the half-open interval [0,1). The documention on cppreference.com of std::generate_canonical confirms this.

                  但是,當我運行以下程序時:

                  However, when I run the following program:

                  #include <iostream>
                  #include <limits>
                  #include <random>
                  
                  int main()
                  {
                      std::mt19937 rng;
                  
                      std::seed_seq sequence{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
                      rng.seed(sequence);
                      rng.discard(12 * 629143 + 6);
                  
                      float random = std::generate_canonical<float,
                                     std::numeric_limits<float>::digits>(rng);
                  
                      if (random == 1.0f)
                      {
                          std::cout << "Bug!
                  ";
                      }
                  
                      return 0;
                  }
                  

                  它給了我以下輸出:

                  Bug!
                  

                  即它為我生成了一個完美的 1,這會導致我的 MC 集成出現問題.這是有效的行為還是我這邊有錯誤?這給出了與 G++ 4.7.3 相同的輸出

                  i.e. it generates me a perfect 1, which causes problems in my MC integration. Is that valid behavior or is there an error on my side? This gives the same output with G++ 4.7.3

                  g++ -std=c++11 test.c && ./a.out
                  

                  和clang 3.3

                  clang++ -stdlib=libc++ -std=c++11 test.c && ./a.out
                  

                  如果這是正確的行為,我該如何避免 1?

                  If this is correct behavior, how can I avoid 1?

                  編輯 1:來自 git 的 G++ 似乎遇到了同樣的問題.我在

                  Edit 1: G++ from git seems to suffer from the same problem. I am on

                  commit baf369d7a57fb4d0d5897b02549c3517bb8800fd
                  Date:   Mon Sep 1 08:26:51 2014 +0000
                  

                  并使用 ~/temp/prefix/bin/c++ -std=c++11 -Wl,-rpath,/home/cschwan/temp/prefix/lib64 test.c && 編譯./a.out 給出相同的輸出,ldd 產生

                  and compiling with ~/temp/prefix/bin/c++ -std=c++11 -Wl,-rpath,/home/cschwan/temp/prefix/lib64 test.c && ./a.out gives the same output, ldd yields

                  linux-vdso.so.1 (0x00007fff39d0d000)
                  libstdc++.so.6 => /home/cschwan/temp/prefix/lib64/libstdc++.so.6 (0x00007f123d785000)
                  libm.so.6 => /lib64/libm.so.6 (0x000000317ea00000)
                  libgcc_s.so.1 => /home/cschwan/temp/prefix/lib64/libgcc_s.so.1 (0x00007f123d54e000)
                  libc.so.6 => /lib64/libc.so.6 (0x000000317e600000)
                  /lib64/ld-linux-x86-64.so.2 (0x000000317e200000)
                  

                  編輯 2:我在此處報告了該行為:https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63176

                  Edit 2: I reported the behavior here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63176

                  編輯 3:clang 團隊似乎意識到了這個問題:http://llvm.org/bugs/show_bug.cgi?id=18767

                  Edit 3: The clang team seems to be aware of the problem: http://llvm.org/bugs/show_bug.cgi?id=18767

                  推薦答案

                  問題出在從 std::mt19937 (std::uint_fast32_t) 的 codomain 映射浮動;如果當前的 IEEE754 舍入模式不是舍入到負無窮大(注意默認值是舍入),那么在發生精度損失時,標準描述的算法會給出不正確的結果(與其對算法輸出的描述不一致)-到最近).

                  The problem is in mapping from the codomain of std::mt19937 (std::uint_fast32_t) to float; the algorithm described by the standard gives incorrect results (inconsistent with its description of the output of the algorithm) when loss of precision occurs if the current IEEE754 rounding mode is anything other than round-to-negative-infinity (note that the default is round-to-nearest).

                  帶有種子的 mt19937 的第 7549723 次輸出是 4294967257 (0xffffffd9u),當四舍五入為 32 位浮點數時給出 0x1p+32,它等于最大值mt19937, 4294967295 (0xffffffffu) 的值,同時四舍五入為 32 位浮點數.

                  The 7549723rd output of mt19937 with your seed is 4294967257 (0xffffffd9u), which when rounded to 32-bit float gives 0x1p+32, which is equal to the max value of mt19937, 4294967295 (0xffffffffu) when that is also rounded to 32-bit float.

                  如果要指定從 URNG 的輸出轉換為 generate_canonicalRealType 時,標準可以確保正確的行為,四舍五入將向負數執行無限;在這種情況下,這將給出正確的結果.作為 QOI,libstdc++ 做出這個改變會很好.

                  The standard could ensure correct behavior if it were to specify that when converting from the output of the URNG to the RealType of generate_canonical, rounding is to be performed towards negative infinity; this would give a correct result in this case. As QOI, it would be good for libstdc++ to make this change.

                  隨著這個變化,1.0 將不再生成;取而代之的是 0 < 的邊界值 0x1.fffffep-NN <= 8 將更頻繁地生成(每個 N 大約 2^(8 - N - 32),具體取決于 MT19937 的實際分布).

                  With this change, 1.0 will no longer be generated; instead the boundary values 0x1.fffffep-N for 0 < N <= 8 will be generated more often (approximately 2^(8 - N - 32) per N, depending on the actual distribution of MT19937).

                  我建議不要直接將 floatstd::generate_canonical 一起使用;而是在 double 中生成數字,然后向負無窮大舍入:

                  I would recommend to not use float with std::generate_canonical directly; rather generate the number in double and then round towards negative infinity:

                      double rd = std::generate_canonical<double,
                          std::numeric_limits<float>::digits>(rng);
                      float rf = rd;
                      if (rf > rd) {
                        rf = std::nextafter(rf, -std::numeric_limits<float>::infinity());
                      }
                  

                  std::uniform_real_distribution 也會出現這個問題;解決方案是相同的,在 double 上專門化分布,并將結果向 float 中的負無窮大舍入.

                  This problem can also occur with std::uniform_real_distribution<float>; the solution is the same, to specialize the distribution on double and round the result towards negative infinity in float.

                  這篇關于1.0 是 std::generate_canonical 的有效輸出嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  read input files, fastest way possible?(讀取輸入文件,最快的方法?)
                  The easiest way to read formatted input in C++?(在 C++ 中讀取格式化輸入的最簡單方法?)
                  Reading from .txt file into two dimensional array in c++(從 .txt 文件讀取到 C++ 中的二維數組)
                  How to simulate a key press in C++(如何在 C++ 中模擬按鍵按下)
                  Why doesn#39;t getline(cin, var) after cin.ignore() read the first character of the string?(為什么在 cin.ignore() 之后沒有 getline(cin, var) 讀取字符串的第一個字符?)
                  What is the cin analougus of scanf formatted input?(scanf 格式輸入的 cin 類比是什么?)
                  <tfoot id='lczBS'></tfoot>
                      <tbody id='lczBS'></tbody>
                  1. <small id='lczBS'></small><noframes id='lczBS'>

                            <bdo id='lczBS'></bdo><ul id='lczBS'></ul>
                            <legend id='lczBS'><style id='lczBS'><dir id='lczBS'><q id='lczBS'></q></dir></style></legend>
                          • <i id='lczBS'><tr id='lczBS'><dt id='lczBS'><q id='lczBS'><span id='lczBS'><b id='lczBS'><form id='lczBS'><ins id='lczBS'></ins><ul id='lczBS'></ul><sub id='lczBS'></sub></form><legend id='lczBS'></legend><bdo id='lczBS'><pre id='lczBS'><center id='lczBS'></center></pre></bdo></b><th id='lczBS'></th></span></q></dt></tr></i><div class="7dpfz9n" id='lczBS'><tfoot id='lczBS'></tfoot><dl id='lczBS'><fieldset id='lczBS'></fieldset></dl></div>
                            主站蜘蛛池模板: 绿萝净除甲醛|深圳除甲醛公司|测甲醛怎么收费|培训机构|电影院|办公室|车内|室内除甲醛案例|原理|方法|价格立马咨询 | 磁力反应釜,高压釜,实验室反应釜,高温高压反应釜-威海自控反应釜有限公司 | 信阳市建筑勘察设计研究院有限公司 | 东莞海恒试验仪器设备有限公司| 浙江栓钉_焊钉_剪力钉厂家批发_杭州八建五金制造有限公司 | 喷播机厂家_二手喷播机租赁_水泥浆洒布机-河南青山绿水机电设备有限公司 | 风淋室生产厂家报价_传递窗|送风口|臭氧机|FFU-山东盛之源净化设备 | 超声波乳化机-超声波分散机|仪-超声波萃取仪-超声波均质机-精浩机械|首页 | 密集柜_档案密集柜_智能密集架_密集柜厂家_密集架价格-智英伟业 密集架-密集柜厂家-智能档案密集架-自动选层柜订做-河北风顺金属制品有限公司 | 称重传感器,测力传感器,拉压力传感器,压力变送器,扭矩传感器,南京凯基特电气有限公司 | 定硫仪,量热仪,工业分析仪,马弗炉,煤炭化验设备厂家,煤质化验仪器,焦炭化验设备鹤壁大德煤质工业分析仪,氟氯测定仪 | 对照品_中药对照品_标准品_对照药材_「格利普」高纯中药标准品厂家-成都格利普生物科技有限公司 澳门精准正版免费大全,2025新澳门全年免费,新澳天天开奖免费资料大全最新,新澳2025今晚开奖资料,新澳马今天最快最新图库 | 接地电阻测试仪[厂家直销]_电缆故障测试仪[精准定位]_耐压测试仪-武汉南电至诚电力设备 | 太空舱_民宿太空舱厂家_移动房屋太空舱价格-豪品建筑 | 动库网动库商城-体育用品专卖店:羽毛球,乒乓球拍,网球,户外装备,运动鞋,运动包,运动服饰专卖店-正品运动品网上商城动库商城网 - 动库商城 | 氮化镓芯片-碳化硅二极管 - 华燊泰半导体 | 双齿辊破碎机-大型狼牙破碎机视频-对辊破碎机价格/型号图片-金联机械设备生产厂家 | 干粉砂浆设备_干混砂浆生产线_腻子粉加工设备_石膏抹灰砂浆生产成套设备厂家_干粉混合设备_砂子烘干机--郑州铭将机械设备有限公司 | 青州搬家公司电话_青州搬家公司哪家好「鸿喜」青州搬家 | EDLC超级法拉电容器_LIC锂离子超级电容_超级电容模组_软包单体电容电池_轴向薄膜电力电容器_深圳佳名兴电容有限公司_JMX专注中高端品牌电容生产厂家 | 东莞螺杆空压机_永磁变频空压机_节能空压机_空压机工厂批发_深圳螺杆空压机_广州螺杆空压机_东莞空压机_空压机批发_东莞空压机工厂批发_东莞市文颖设备科技有限公司 | 福州时代广告制作装饰有限公司-福州广告公司广告牌制作,福州展厅文化墙广告设计, | QQ房产导航-免费收录优秀房地产网站_房地产信息网 | 莱州网络公司|莱州网站建设|莱州网站优化|莱州阿里巴巴-莱州唯佳网络科技有限公司 | 招商帮-一站式网络营销服务|互联网整合营销|网络推广代运营|信息流推广|招商帮企业招商好帮手|搜索营销推广|短视视频营销推广 | 建筑工程资质合作-工程资质加盟分公司-建筑资质加盟 | 江苏全风,高压风机,全风环保风机,全风环形高压风机,防爆高压风机厂家-江苏全风环保科技有限公司(官网) | 合肥白癜风医院_[治疗白癜风]哪家好_合肥北大白癜风医院 | 阜阳在线-阜阳综合门户| 远程会诊系统-手术示教系统【林之硕】医院远程医疗平台 | 纳米涂料品牌 防雾抗污纳米陶瓷涂料厂家_虹瓷科技 | 北京森语科技有限公司-模型制作专家-展览展示-沙盘模型设计制作-多媒体模型软硬件开发-三维地理信息交互沙盘 | 济南货架定做_仓储货架生产厂_重型货架厂_仓库货架批发_济南启力仓储设备有限公司 | 喷码机,激光喷码打码机,鸡蛋打码机,手持打码机,自动喷码机,一物一码防伪溯源-恒欣瑞达有限公司 | 餐饮小吃技术培训-火锅串串香培训「何小胖培训」_成都点石成金[官网] | 活性炭厂家-蜂窝活性炭-粉状/柱状/果壳/椰壳活性炭-大千净化-活性炭 | HV全空气系统_杭州暖通公司—杭州斯培尔冷暖设备有限公司 | 废气处理_废气处理设备_工业废气处理_江苏龙泰环保设备制造有限公司 | 锤式粉碎机,医药粉碎机,锥式粉碎机-无锡市迪麦森机械制造有限公司 | PAS糖原染色-CBA流式多因子-明胶酶谱MMP-上海研谨生物科技有限公司 | 消电检公司,消电检价格,北京消电检报告-北京设施检测公司-亿杰(北京)消防工程有限公司 |