-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
44 lines (41 loc) · 8.37 KB
/
index.html
File metadata and controls
44 lines (41 loc) · 8.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"
/>
<link rel="stylesheet" href="/umi.eb884056.css" />
<script>
window.routerBase = "/";
</script>
<script>
//! umi version: 3.3.1
</script>
<script
src="https://www.googletagmanager.com/gtag/js?id=UA-89371431-6"
async="true"
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "UA-89371431-6");
</script>
<title>Integer and Floating-Point</title>
</head>
<body>
<div id="root"><div class="__dumi-default-layout" data-show-sidemenu="true" data-show-slugs="true" data-site-mode="true" data-gapless="false"><div class="__dumi-default-navbar" data-mode="site"><button class="__dumi-default-navbar-toggle"></button><a class="__dumi-default-navbar-logo" href="/en-US">StaticScript</a><nav><div class="__dumi-default-search"><input type="search" class="__dumi-default-search-input" value=""/><ul></ul></div><a aria-current="page" class="active" href="/en-US/guide">Guide</a><a target="_blank" rel="noopener noreferrer" href="https://github.com/StaticScript/StaticScript">GitHub<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="__dumi-default-external-link-icon"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a><div class="__dumi-default-locale-select" data-locale-count="2"><span>中文</span></div></nav></div><div class="__dumi-default-menu" data-mode="site"><div class="__dumi-default-menu-inner"><div class="__dumi-default-menu-header"><a class="__dumi-default-menu-logo" href="/en-US"></a><h1>StaticScript</h1><p></p></div><div class="__dumi-default-menu-mobile-area"><ul class="__dumi-default-menu-nav-list"><li><a aria-current="page" class="active" href="/en-US/guide">Guide</a></li><li><a target="_blank" rel="noopener noreferrer" href="https://github.com/StaticScript/StaticScript">GitHub<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="__dumi-default-external-link-icon"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul><div class="__dumi-default-locale-select" data-locale-count="2"><span>中文</span></div></div><ul class="__dumi-default-menu-list"><li><a href="/en-US/guide">Introduction</a></li><li><a href="/en-US/guide/install">Installation</a></li><li><a href="/en-US/guide/getting-started">Quick Start</a></li><li><a href="/en-US/guide/type">Type</a></li><li><a href="/en-US/guide/variable&constant">Variable and Constant</a></li><li><a href="/en-US/guide/literal">Literal</a></li><li><a href="/en-US/guide/operators">Operators</a></li><li><a aria-current="page" class="active" href="/en-US/guide/integer&float">Integer and Floating-Point</a></li></ul></div></div><ul class="__dumi-default-layout-toc" role="slug-list"><li title="类型提升" data-depth="2" class=""><a href="/en-US/guide/integer&float#类型提升"><span>类型提升</span></a></li><li title="整型转浮点型" data-depth="2" class=""><a href="/en-US/guide/integer&float#整型转浮点型"><span>整型转浮点型</span></a></li><li title="浮点型转整型" data-depth="2" class=""><a href="/en-US/guide/integer&float#浮点型转整型"><span>浮点型转整型</span></a></li></ul><div class="__dumi-default-layout-content"><div class="markdown"><p>In StaticScript, integers and floats are considered to be the same type, both of which are numeric.</p><p>To be compatible with typescript, set type <code>number</code> as float-point and <code>int</code> as integer.</p><h2 id="类型提升"><a aria-hidden="true" href="#类型提升"><span class="icon icon-link"></span></a>类型提升</h2><p>When binary operators are used to operate integers and floating-point numbers, the left operator is floating-point number or the right operator is floating-point number, which will result in floating-point operation, for example</p><div class="__dumi-default-code-block"><pre class="prism-code language-ts"><button title="" type="button" class="__dumi-default-icon __dumi-default-btn-copy __dumi-default-code-block-copy-btn" data-clipboard-text="let x: int = 10;
let y: number = 11.1;
let z = x + y;
" data-status="copy"></button><div class="token-line"><span class="token keyword">let</span><span class="token plain"> x</span><span class="token punctuation">:</span><span class="token plain"> int </span><span class="token operator">=</span><span class="token plain"> </span><span class="token number">10</span><span class="token punctuation">;</span><span class="token plain"></span></div><div class="token-line"><span class="token plain"></span></div><div class="token-line"><span class="token plain"></span><span class="token keyword">let</span><span class="token plain"> y</span><span class="token punctuation">:</span><span class="token plain"> </span><span class="token builtin">number</span><span class="token plain"> </span><span class="token operator">=</span><span class="token plain"> </span><span class="token number">11.1</span><span class="token punctuation">;</span><span class="token plain"></span></div><div class="token-line"><span class="token plain"></span></div><div class="token-line"><span class="token plain"></span><span class="token keyword">let</span><span class="token plain"> z </span><span class="token operator">=</span><span class="token plain"> x </span><span class="token operator">+</span><span class="token plain"> y</span><span class="token punctuation">;</span><span class="token plain"></span></div><div class="token-line"><span class="token plain"></span></div></pre></div><p>The variable x is integer, the variable y is floating-point, and the type of variable z storing the operation result is floating-point.</p><h2 id="整型转浮点型"><a aria-hidden="true" href="#整型转浮点型"><span class="icon icon-link"></span></a>整型转浮点型</h2><p>In addition to type promotion, there are three situations that cause an integer to become a floating-point.</p><ul><li>Assign an integer value to a variable whose explicit type is floating-point. The integer value will be converted to floating-point type and then stored on the variable (the same is true for constants).</li><li>If the function parameter is a floating-point type and the actual argument is an integer type, the argument will be converted to a floating-point type first and then passed to the function parameter.</li><li>The explicit type of array is floating-point array, but the value of array element is integer. The element will be converted to floating-point type first and then stored in the array (including multidimensional array).</li></ul><h2 id="浮点型转整型"><a aria-hidden="true" href="#浮点型转整型"><span class="icon icon-link"></span></a>浮点型转整型</h2><p>There are three conditions that cause floating-point to be converted to integer.</p><ul><li>Assign a floating-point constant to a variable whose explicit type is integer. The floating-point constant will be converted to integer and then stored on the variable (the same for constant).</li><li>If the function parameter is integer and the argument is floating point, the argument will be converted to integer and then passed to the function parameter.</li><li>The explicit type of the array is an integer array, but the array element value is a floating-point type. The element will be converted to an integer first and then stored in the array (including multidimensional array).</li></ul></div><div class="__dumi-default-layout-footer-meta"><span data-updated-text="Last Update: ">12/19/2020, 2:19:33 PM</span></div></div></div></div>
<script>
window.g_useSSR = true;
window.g_initialProps = {};
</script>
<script src="/umi.63dc6bce.js"></script>
</body>
</html>