双浮点数 计算

没整理 好乱 凑活看吧 用来计算这个崩溃大陆修改的 方便了好多 自动复制 自动转换

<!-- saved from url=(0017)http://moqiu.xyz/ -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

  <title></title>
</head>

<body>
  <h1>双浮点计算</h1>原始数据:

  <form>
    <input id="num1" type="text" value="1" onkeyup="count(this);" /><br />
    双浮点数据: <input id="result1" type="text" value="1072693248" /><br />
    <input id="ger" type="button" value="转换" /><button class="copy">复制内容</button><br />
    <button class="copy2">复制最大内容</button> <script language="javascript" type="text/javascript">
    <script language="javascript">
                function count(el)
                {
                        gogogo();
                        copy(document.getElementById("result1").value);
                        document.getElementById("num1").focus();

                }
                function copy(text) {
                        var text=window.document.getElementById("result1").value;
                        copyTextToClipboard(text)
                }
                var copyBtn = document.querySelector('.copy2')
                        //1088611872
                  // 点击的时候调用 copyTextToClipboard() 方法就好了.
                  copyBtn.onclick = function() {
                        //var text=window.document.getElementById("result1").value;
                        copyTextToClipboard('1088611872')
                  }

                var copyBtn = document.querySelector('.copy')
                        //1088611872
                  // 点击的时候调用 copyTextToClipboard() 方法就好了.
                  copyBtn.onclick = function() {
                        var text=window.document.getElementById("result1").value;
                        copyTextToClipboard(text)
                  }

                var Iger = window.document.getElementById("ger");
                var r = window.document.getElementById("result1");

                Iger.onclick = gogogo;

                function checkNum() {
                        var vnum1 = window.document.getElementById("num1").value;
                        return isNaN(vnum1) ? null : vnum1;
                }

                function cal(a) {
                        if (a != null)
                                return 1072693248
                                                + Math.pow(2, (20 - Math.floor(Math.log(a)
                                                                / Math.log(2))))
                                                * (a - Math.pow(2, (Math.floor(Math.log(a)
                                                                / Math.log(2))))) + Math.pow(2, 20)
                                                * Math.floor(Math.log(a) / Math.log(2));
                        else
                                return null;
                }

                function coutRes(b) {
                        if (b != null)
                                r.value = b;
                        else
                                r.value = "输入错误";
                }

                function gogogo() {
                        r.value = "";
                        coutRes(cal(checkNum()));
                }

                function copyTextToClipboard(text) {
                        var textArea = document.createElement("textarea")

                        textArea.style.position = 'fixed'
                        textArea.style.top = 0
                        textArea.style.left = 0
                        textArea.style.width = '2em'
                        textArea.style.height = '2em'
                        textArea.style.padding = 0
                        textArea.style.border = 'none'
                        textArea.style.outline = 'none'
                        textArea.style.boxShadow = 'none'
                        textArea.style.background = 'transparent'
                        textArea.value = text

                        document.body.appendChild(textArea)

                        textArea.select()

                        try {
                          var msg = document.execCommand('copy') ? '成功' : '失败'
                          console.log('复制内容 ' + msg)
                        } catch (err) {
                          console.log('不能使用这种方法复制内容')
                        }

                        document.body.removeChild(textArea)
                }
    </script>
  </form>
</body>
</html>
Last modification:October 14th, 2017 at 11:15 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment