Integer literal

In computer science, an integer literal is a kind of literal for an integer whose value is directly represented in source code. For example, in the assignment statement x = 1, the string 1 is an integer literal indicating the value 1, while in the statement x = 0x10 the string 0x10 is an integer literal indicating the value 16, which is represented by 10 in hexadecimal (indicated by the 0x prefix).

By contrast, in x = cos(0), the expression cos(0) evaluates to 1 (as the cosine of 0), but the value 1 is not literally included in the source code. More simply, in x = 2 + 2, the expression 2 + 2 evaluates to 4, but the value 4 is not literally included. Further, in x = "1" the "1" is a string literal, not an integer literal, because it is in quotes. The value of the string is 1, which happens to be an integer string, but this is semantic analysis of the string literal – at the syntactic level "1" is simply a string, no different from "foo".

Parsing

Recognizing a string (sequence of characters in the source code) as an integer literal is part of the lexical analysis (lexing) phase, while evaluating the literal to its value is part of the semantic analysis phase. Within the lexer and phrase grammar, the token class is often denoted integer, with the lowercase indicating a lexical-level token class, as opposed to phrase-level production rule (such as ListOfIntegers). Once a string has been lexed (tokenized) as an integer literal, its value cannot be determined syntactically (it is just an integer), and evaluation of its value becomes a semantic question.

Integer literals are generally lexed with regular expressions, as in Python.[1]

Evaluation

As with other literals, integer literals are generally evaluated at compile time, as part of the semantic analysis phase. In some cases this semantic analysis is done in the lexer, immediately on recognition of an integer literal, while in other cases this is deferred until the parsing stage, or until after the parse tree has been completely constructed. For example, on recognizing the string 0x10 the lexer could immediately evaluate this to 16 and store that (a token of type integer and value 16), or defer evaluation and instead record a token of type integer and value 0x10.

Once literals have been evaluated, further semantic analysis in the form of constant folding is possible, meaning that literal expressions involving literal values can be evaluated at the compile phase. For example, in the statement x = 2 + 2 after the literals have been evaluated and the expression 2 + 2 has been parsed, it can then be evaluated to 4, though the value 4 does not itself appear as a literal.

Affixes

Integer literals frequently have prefixes indicating base, and less frequently suffixes indicating type.[1] For example, in C++ 0x10ULL indicates the value 16 (because hexadecimal) as an unsigned long long integer.

Common prefixes include:

Common suffixes include:

  • l or L for long integer;
  • ll or LL for long long integer;
  • u or U for unsigned integer.

These affixes are somewhat similar to sigils, though sigils attach to identifiers (names), not literals.

Digit separators

In some languages, integer literals may contain digit separators to allow digit grouping into more legible forms. If this is available, it can usually be done for floating point literals as well. This is particularly useful for bit fields and makes it easier to see the size of large numbers (such as a million) at a glance by subitizing rather than counting digits. It is also useful for numbers that are typically grouped, such as credit card number or social security numbers.[a] Very long numbers can be further grouped by doubling up separators.

Typically decimal numbers (base-10) are grouped in three digit groups (representing one of 1000 possible values), binary numbers (base-2) in four digit groups (one nibble, representing one of 16 possible values), and hexadecimal numbers (base-16) in two digit groups (each digit is one nibble, so two digits are one byte, representing one of 256 possible values). Numbers from other systems (such as id numbers) are grouped following whatever convention is in use.

Examples

In Ada,[2][3] C# (from version 7.0), D, Eiffel, Go (from version 1.13),[4] Haskell (from GHC version 8.6.1),[5] Java (from version 7),[6] Julia, Perl, Python (from version 3.6),[7] Ruby, Rust[8] and Swift,[9] integer literals and float literals can be separated with an underscore (_). There can be some restrictions on placement; for example, in Java they cannot appear at the start or end of the literal, nor next to a decimal point. While the period, comma, and (thin) spaces are used in normal writing for digit separation, these conflict with their existing use in programming languages as radix point, list separator (and in C/C++, the comma operator), and token separator.

Examples include:

int oneMillion = 1_000_000;
int creditCardNumber = 1234_5678_9012_3456;
int socialSecurityNumber = 123_45_6789;

In C++14 (2014) and the next version of C as of 2022, C23, the apostrophe character may be used to separate digits arbitrarily in numeric literals.[10][11] The underscore was initially proposed, with an initial proposal in 1993,[12] and again for C++11,[13] following other languages. However, this caused conflict with user-defined literals, so the apostrophe was proposed instead, as an "upper comma" (which is used in some other contexts).[14][15]

auto integer_literal = 1'000'000;
auto binary_literal = 0b0100'1100'0110;
auto very_long_binary_literal =
    0b0000'0001'0010'0011''0100'0101'0110'0111;

Notes

  1. ^ Typically sensitive numbers such as these would not be included as literals, however.

References

  1. ^ a b "2.4.4. Integer and long integer literals"
  2. ^ "Ada '83 Language Reference Manual: 2.4. Numeric Literals".
  3. ^ ""Rationale for the Design of the Ada® Programming Language": 2.1 Lexical Structure".
  4. ^ "Go 1.13 Release Notes - Changes to the language". Retrieved 2020-11-05.
  5. ^ "Glasgow Haskell Compiler User's Guide: 11.3.7. Numeric underscores". Retrieved 2019-01-31.
  6. ^ "Underscores in Numeric Literals". Retrieved 2015-08-12.
  7. ^ "What's New In Python 3.6".
  8. ^ "Literals and operators". Retrieved 2019-11-15.
  9. ^ "The Swift Programming Language: Lexical Structure".
  10. ^ Crowl, Lawrence; Smith, Richard; Snyder, Jeff; Vandevoorde, Daveed (25 September 2013). "N3781 Single-Quotation-Mark as a Digit Separator" (PDF).
  11. ^ Aaron Ballman (2020-12-15). "N2626: Digit separators" (PDF).
  12. ^ John Max Skaller (March 26, 1993). "N0259: A Proposal to allow Binary Literals, and some other small changes to Chapter 2: Lexical Conventions" (PDF).
  13. ^ Crowl, Lawrence (2007-05-02). "N2281: Digit Separators".
  14. ^ Vandevoorde, Daveed (2012-09-21). "N3448: Painless Digit Separation" (PDF).
  15. ^ Crowl, Lawrence (2012-12-19). "N3499: Digit Separators".

Read other articles:

A PortuguesaB. Indonesia: PortugisLembaran musik dan lirik (1957)Lagu kebangsaan PortugalPenulis lirikHenrique Lopes de Mendonça, 1890KomponisAlfredo Keil, 1890Penggunaan5 Oktober 1910 (de facto)19 Juli 1911 (de jure)Sampel audioA Portuguesa (instrumen)berkasbantuan Sampel audioA Portuguesaberkasbantuan A Portuguesa (Indonesia: Lagu Portugiscode: id is deprecated ), pengucapan bahasa Portugis: [ɐ puɾtuˈɣezɐ], adalah lagu kebangsaan Portugal. Lagu ini hasil gubahan Alfredo Keil...

 

This article does not cite any sources. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Two Fathers TV series – news · newspapers · books · scholar · JSTOR (October 2015) (Learn how and when to remove this template message) Taiwanese TV series or program Two FathersPromotional posterAlso known as兩個爸爸GenreTaiwanese dramaWritten byShaohui TingShiheng Hua...

 

School in Mankato, Minnesota, United StatesMankato West High SchoolMankato West ScarletsAddress1351 South Riverfront DriveMankato, MinnesotaUnited StatesCoordinates44°09′32″N 94°01′04″W / 44.1589°N 94.01765°W / 44.1589; -94.01765InformationSchool districtIndependent School District 77PrincipalSherri BlasingTeaching staff68.15 (FTE)[2]Grades9-12Number of students1,222 (2017-18)[2]Student to teacher ratio17.93[2]Color(s)Scarlet and Whi...

ممثل بلباس امرأةفرع من فنان أداءtransformist (en) تعديل - تعديل مصدري - تعديل ويكي بيانات الدراق كوين ڤايليت تشاتشكي الفائزة في روبول دراق ريس في موسمه السابع[1] في ابريل 2017 الدراق كوين (بالإنجليزية: Drag Queen)‏ هم في الغالب من الرجال يرتدون الملابس النسائية ويتصرفون بإنوثة مبالغ ف�...

 

2020 single by Lil Uzi VertSasukeSingle by Lil Uzi VertReleasedApril 24, 2020 (2020-04-24)GenreTrapLength4:11LabelAtlanticSongwriter(s)Symere WoodsProducer(s)Brandon FinessinOuttatownLil Uzi Vert singles chronology That Way (2020) Sasuke (2020) Count a Million (2020) Audio videoSasuke on YouTube Sasuke is a song by American rapper Lil Uzi Vert. It was released on April 24, 2020 and serves as the lead single of their upcoming third studio album.[1][2][3] ...

 

U.S. Navy physician, researcher, and educator Charles Wesley Shilling, MDNickname(s)ChuckBorn(1901-09-21)September 21, 1901Upland, IndianaDiedDecember 23, 1994(1994-12-23) (aged 93)Fredericksburg, VirginiaPlace of burialArlington National CemeteryAllegiance United States of AmericaService/branchUnited States NavyYears of service1927–1955RankCaptainAwardsGolden Cross of the Order of the Phoenix Captain Charles Wesley Shilling (September 21, 1901 – December 23, 1994) was an A...

У Вікіпедії є статті про інші значення цього терміна: 1330 (значення). Рік: 1327 · 1328 · 1329 — 1330 — 1331 · 1332 · 1333 Десятиліття: 1310-ті · 1320-ті — 1330-ті — 1340-ві · 1350-ті Століття: XII · XIII —  XIV — XV · XVI Тисячоліття: 1-ше — 2-ге — 3-тє 1330 в інших календаря...

 

Sceaux 行政国 フランス地域圏 (Région) イル=ド=フランス地域圏県 (département) オー=ド=セーヌ県郡 (arrondissement) アントニー郡小郡 (canton) 小郡庁所在地INSEEコード 92071郵便番号 92330市長(任期) フィリップ・ローラン(2008年-2014年)自治体間連合 (fr) メトロポール・デュ・グラン・パリ人口動態人口 19,679人(2007年)人口密度 5466人/km2住民の呼称 Scéens地理座標 北緯48度4...

 

この項目には、一部のコンピュータや閲覧ソフトで表示できない文字が含まれています(詳細)。 数字の大字(だいじ)は、漢数字の一種。通常用いる単純な字形の漢数字(小字)の代わりに同じ音の別の漢字を用いるものである。 概要 壱万円日本銀行券(「壱」が大字) 弐千円日本銀行券(「弐」が大字) 漢数字には「一」「二」「三」と続く小字と、「壱」「�...

Private university in Honchō, Nakano, Tokyo Tokyo Polytechnic University東京工芸大学TypePrivateEstablishedFounded 1923,Chartered 1966PresidentNobuyuki KobayashiLocationTokyo, JapanCampusNakano, Tokyo, Atsugi, KanagawaWebsitewww.t-kougei.ac.jp/e/ Tokyo Polytechnic University (東京工芸大学, Tōkyō Kōgei Daigaku) is a private university in Honchō, Nakano, Tokyo. Its nickname is Shadai (写大). It was formerly known as Tokyo College of Photography (東京写真大学, Tōkyō Sha...

 

此條目可参照英語維基百科相應條目来扩充。 (2021年5月6日)若您熟悉来源语言和主题,请协助参考外语维基百科扩充条目。请勿直接提交机械翻译,也不要翻译不可靠、低品质内容。依版权协议,译文需在编辑摘要注明来源,或于讨论页顶部标记{{Translated page}}标签。 约翰斯顿环礁Kalama Atoll 美國本土外小島嶼 Johnston Atoll 旗幟颂歌:《星條旗》The Star-Spangled Banner約翰斯頓環礁�...

 

2020年夏季奥林匹克运动会波兰代表團波兰国旗IOC編碼POLNOC波蘭奧林匹克委員會網站olimpijski.pl(英文)(波兰文)2020年夏季奥林匹克运动会(東京)2021年7月23日至8月8日(受2019冠状病毒病疫情影响推迟,但仍保留原定名称)運動員206參賽項目24个大项旗手开幕式:帕维尔·科热尼奥夫斯基(游泳)和马娅·沃什乔夫斯卡(自行车)[1]闭幕式:卡罗利娜·纳亚(皮划艇)&#...

Peta jarak ke pesisir terdekat[1] (termasuk pulau laut, tidak termasuk danau). Titik merah berarti titik terpencil daratan utama, Britania Raya, dan Semenanjung Iberia. Garis tipisnya terpisah sejauh 250 km (160 mi), sedangkan garis tebalnya terpisah sejauh 1.000 km (620 mi). Titik terpencil merupakan tempat yang paling menantang atau sulit untuk dicapai karena sangat jauh dari suatu bentang geografis. Umumnya istilah ini mengacu ke titik terjauh dari bibir pantai....

 

Upper house of the German Empire's parliament This article is about the Bundesrat of the German Empire (1871–1918). For the current legislative body, see German Bundesrat. Bundesrat Deutscher BundesratLegislative body of GermanyTypeTypeUpper house HistoryEstablished1871Disbanded1918Preceded byBundesrat of the North German ConfederationSucceeded byReichsrat of the Weimar RepublicSeats61 (at dissolution)ElectionsVoting systemAppointedMeeting placeLeipziger Straße 4, Berlin (1871–...

 

Prime Minister of the United Kingdom from 1902 to 1905 This article is about the politician. For the steel manufacturer, see Arthur Balfour, 1st Baron Riverdale. Lord Balfour redirects here. For the titles in the peerages of Scotland, Ireland, and the United Kingdom, see Baron Balfour of Glenawley, Baron Balfour of Inchrye, Earl of Balfour, and Lord Balfour of Burleigh. The Right HonourableThe Earl of BalfourKG OM PC FRS FBA DLPortrait by George Charles Beresford, 1902Prim...

Semi-automatic pistol Beholla Pistol The Beholla pistol made in 1915 for the German forces in WWITypeSemi-automatic pistolPlace of originGerman EmpireService historyUsed byGermanyWarsWorld War ILithuanian Wars of IndependenceWorld War IIProduction historyDesignerBecker & HollanderManufacturerWaffenfabrik August Menz of SuhlProduced1915–1918No. built45,000SpecificationsMass640 g (23 oz)Length140 mm (5.5 in)Barrel length75 mm (3.0 in)...

 

US Army augmented reality headset Integrated Visual Augmentation System Soldier dons IVAS 1.2 Prototype during user assessment.TypeAugmented reality headsetPlace of originUnited StatesProduction historyDesignerMicrosoftDesigned2018SpecificationsWeight3.4 lb (1.5 kg) The Integrated Visual Augmentation System (IVAS) is an augmented reality headset being developed by Microsoft for the United States Army. It is intended to improve situational awareness by overlaying sensor ima...

 

This article is about the associative property in mathematics. For associativity in the central processing unit memory cache, see CPU cache § Associativity. For associativity in programming languages, see operator associativity. For the meaning of an associated group of people in linguistics, see Associativity (linguistics). Associative and non-associative redirect here. For associative and non-associative learning, see Learning § Types. Property of a mathematical operation This a...

أرض سوبارتو (بالأكدية: سوبارتوم، صوبارتوم.[1][2] بالسومرية: سوبار، صوبار)، هي من منطقة مذكورة في عدة كتابات من العصر البرونزي، ورد أسم المنطقة تحت أسم سوباري في رسائل تل العمارنة، كما سميت ب-صبر في أوغاريت. يعتقد الباحثون بأن سوبارتو كان كياناً سياسيا تحت تأثير الحور�...

 

Greek film, television, theater, and voice actor This biography of a living person does not include any references or sources. Please help by adding reliable sources. Contentious material about living people that is unsourced or poorly sourced must be removed immediately.Find sources: Gerasimos Skiadaresis – news · newspapers · books · scholar · JSTOR (December 2023) (Learn how and when to remove this message) Gerasimos SkiadaresisΓεράσιμος Σ...