gpt4 book ai didi

Ada 数字文字和下划线

转载 作者:行者123 更新时间:2023-12-04 18:10:32 25 4
gpt4 key购买 nike

这是来自在线 Ada 引用手册:
http://www.adaic.org/resources/add_content/standards/05rm/RM.pdf(第 2.3 节)

A decimal_literal is a numeric_literal in the conventional decimal notation (that is, the base is ten). 
Syntax
decimal_literal ::= numeral [.numeral] [exponent]
**numeral ::= digit {[underline] digit}**
exponent ::= E [+] numeral | E – numeral
digit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
An exponent for an integer literal shall not have a minus sign.
Static Semantics
**An underline character in a numeric_literal does not affect its meaning.** The letter E of an exponent can be
written either in lower case or in upper case, with the same meaning.

如果我做
my_literal ::= 123_456;

下划线(下划线)是什么意思? 它说它不影响 的含义。那它有什么用呢?我相信有一个简单的答案,但阅读并重新阅读这篇文章并没有帮助我。

最佳答案

这与货币或 [其他大] 数字中的逗号 (,) 的原因相同:分组。
因此:



Million : Constant:= 1_000_000;

此外,您可以将它与 base-setting 结合使用作为掩蔽设置:

Type Bit is Range 1..8;
SubType Byte is Interfaces.Unsigned_8;
Type Masks is Array(Positive Range <>) of Byte;

Mask_Map : Constant Masks(Bit):=
(
2#0000_0001#,
2#0000_0010#,
2#0000_0100#,
2#0000_1000#,
2#0001_0000#,
2#0010_0000#,
2#0100_0000#,
2#1000_0000#
);

那么也许你可以将 Mask_Map 和 bits 与 or 一起使用, and , 和 xor进行位操作。上面的方法可能看起来比简单定义大量常量并直接操作它们更有效,但它更灵活,您可以稍后将其更改为函数而不必更改任何客户端代码,这可以如果该函数的结果是一个参数化的整数,其中 bit 的定义为 1..PARAMETER'Size,则更有用。 .

关于Ada 数字文字和下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15263400/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com