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

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

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

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

      如何自己編寫冪函數?

      How can I write a power function myself?(如何自己編寫冪函數?)

    3. <tfoot id='LFjg7'></tfoot>

        • <bdo id='LFjg7'></bdo><ul id='LFjg7'></ul>

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

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

            <tbody id='LFjg7'></tbody>

            <legend id='LFjg7'><style id='LFjg7'><dir id='LFjg7'><q id='LFjg7'></q></dir></style></legend>

              • 本文介紹了如何自己編寫冪函數?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我一直想知道如何自己制作一個計算冪的函數(例如 23).在大多數語言中,這些都包含在標準庫中,主要是作為 pow(double x, double y),但我如何自己編寫?

                I was always wondering how I can make a function which calculates the power (e.g. 23) myself. In most languages these are included in the standard library, mostly as pow(double x, double y), but how can I write it myself?

                我在考慮 for 循環,但它認為我的大腦陷入了循環(當我想用非整數指數計算冪時,例如 54.5 或底片 2-21) 然后我瘋了 ;)

                I was thinking about for loops, but it think my brain got in a loop (when I wanted to do a power with a non-integer exponent, like 54.5 or negatives 2-21) and I went crazy ;)

                那么,如何編寫一個計算實數冪的函數?謝謝

                So, how can I write a function which calculates the power of a real number? Thanks

                哦,也許需要注意的是:我不能使用使用冪的函數(例如 exp),這會使它最終變得毫無用處.

                Oh, maybe important to note: I cannot use functions which use powers (e.g. exp), which would make this ultimately useless.

                推薦答案

                負冪不是問題,它們只是正冪的倒數 (1/x).

                Negative powers are not a problem, they're just the inverse (1/x) of the positive power.

                浮點運算稍微復雜一點;如您所知,分數冪等效于根(例如 x^(1/2) == sqrt(x)),并且您還知道以相同的基數乘冪等效于將它們的相加指數.

                Floating point powers are just a little bit more complicated; as you know a fractional power is equivalent to a root (e.g. x^(1/2) == sqrt(x)) and you also know that multiplying powers with the same base is equivalent to add their exponents.

                有了以上所有內容,您可以:

                With all the above, you can:

                • 將指數分解為整數部分和有理部分.
                • 使用循環計算整數冪(您可以優化它分解因子并重用部分計算).
                • 使用您喜歡的任何算法計算根(任何迭代近似,如二分法或牛頓法都可以).
                • 將結果相乘.
                • 如果指數為負,則應用倒數.

                示例:

                2^(-3.5) = (2^3 * 2^(1/2)))^-1 = 1 / (2*2*2 * sqrt(2))
                

                這篇關于如何自己編寫冪函數?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                相關文檔推薦

                In what ways do C++ exceptions slow down code when there are no exceptions thown?(當沒有異常時,C++ 異常會以何種方式減慢代碼速度?)
                Why catch an exception as reference-to-const?(為什么要捕獲異常作為對 const 的引用?)
                When and how should I use exception handling?(我應該何時以及如何使用異常處理?)
                Scope of exception object in C++(C++中異常對象的范圍)
                Catching exceptions from a constructor#39;s initializer list(從構造函數的初始化列表中捕獲異常)
                Difference between C++03 throw() specifier C++11 noexcept(C++03 throw() 說明符 C++11 noexcept 之間的區別)

                <small id='73ofw'></small><noframes id='73ofw'>

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

                  1. <legend id='73ofw'><style id='73ofw'><dir id='73ofw'><q id='73ofw'></q></dir></style></legend>
                      • <tfoot id='73ofw'></tfoot>
                        • <bdo id='73ofw'></bdo><ul id='73ofw'></ul>
                        • 主站蜘蛛池模板: 国产最好的av国产大片 | 91精品久久久久久久久久 | 亚洲精品综合 | 麻豆va | 999久久久免费精品国产 | 国产婷婷精品av在线 | 龙珠z在线观看 | 精品国产精品三级精品av网址 | 天堂一区二区三区 | 成人免费视频在线观看 | 精品一区二区在线观看 | 在线激情视频 | 久久久新视频 | 国产成人精品区一区二区不卡 | 国产精品中文字幕在线 | 久久久精品 | 日韩亚洲一区二区 | 欧美日韩电影一区 | 天天久久| 亚洲成人一区二区 | 欧美精品三区 | 日本成人在线网址 | 日韩精品免费一区 | 久久国产高清 | 九九热免费在线观看 | 日批av| 久久久精品一区二区三区四季av | 黄色免费网站在线看 | 精品在线看| 久久久久久91香蕉国产 | 国产wwwcom | 日韩久久在线 | 欧美日韩淫片 | 激情视频网站 | 亚洲欧美日韩系列 | 国产精品精品视频一区二区三区 | 中文字幕av在线一二三区 | 国产免费观看久久黄av片涩av | 农夫在线精品视频免费观看 | 一区二区三区在线免费观看 | 久久婷婷国产麻豆91 |