Comparison of programming languages (basic instructions): Difference between revisions

Content deleted Content added
fix link
No edit summary
Tags: Reverted nowiki added Visual edit
Line 1:
<nowiki>Insert non-formatted text here</nowiki>{{cleanup HTML|date=February 2019}}
{{Refimprove|date=February 2009}}
{{ProgLangCompare}}
Line 12:
 
=== [[Integer (computer science)|Integer]]s ===
{| class="wikitable sortable"
! rowspan=2|
! colspan=2| 8 bit ([[byte]])
! colspan=2| 16 bit ([[short integer]])
! colspan=2| 32 bit
! colspan=2| 64 bit ([[long integer]])
! colspan=2| Word size
! rowspan=2| Arbitrarily precise ([[Arbitrary-precision arithmetic|bignum]])
|-
! Signed
! Unsigned
! Signed
! Unsigned
! Signed
! Unsigned
! Signed
! Unsigned
! Signed
! Unsigned
|-
| [[Ada (programming language)|Ada]]<ref name=Ada_RM_2012>Ada Reference Manual – Language and Standard Libraries; ISO/IEC 8652:201x (E), {{cite web |url=http://www.ada-auth.org/standards/12rm/RM-Final.pdf |title=Reference Manual |accessdate=2013-07-19 |url-status=dead |archiveurl=https://web.archive.org/web/20110427190723/http://www.ada-auth.org/standards/12rm/RM-Final.pdf |archivedate=2011-04-27 }}</ref>
| <code>range -2**7 .. 2**7 - 1</code>{{ref|Ada_range|[j]}}
| <code>range 0 .. 2**8 - 1</code>{{ref|Ada_range|[j]}} or <code>mod 2**8</code>{{ref|Ada_mod|[k]}}
| <code>range -2**15 .. 2**15 - 1</code>{{ref|Ada_range|[j]}}
| <code>range 0 .. 2**16 - 1</code>{{ref|Ada_range|[j]}} or <code>mod 2**16</code>{{ref|Ada_mod|[k]}}
| <code>range -2**31 .. 2**31 - 1</code>{{ref|Ada_range|[j]}}
| <code>range 0 .. 2**32 - 1</code>{{ref|Ada_range|[j]}} or <code>mod 2**32</code>{{ref|Ada_mod|[k]}}
| <code>range -2**63 .. 2**63 - 1</code>{{ref|Ada_range|[j]}}
| <code>mod 2**64</code>{{ref|Ada_mod|[k]}}
| <code>Integer</code>{{ref|Ada_range|[j]}}
| <code>range 0 .. 2**Integer'<wbr/>Size - 1</code>{{ref|Ada_range|[j]}} or <code>mod Integer'<wbr/>Size</code>{{ref|Ada_mod|[k]}}
| {{n/a}}
|-
| rowspan=2| [[ALGOL 68]] (variable-width)
| rowspan=2| <code>short short int</code>{{ref|CInt|[c]}}
| rowspan=2 {{n/a}}
| rowspan=2| <code>short int</code>{{ref|CInt|[c]}}
| rowspan=2 {{n/a}}
| rowspan=2| <code>int</code>{{ref|CInt|[c]}}
| rowspan=2 {{n/a}}
| rowspan=2| <code>long int</code>{{ref|CInt|[c]}}
| rowspan=2 {{n/a}}
| <code>int</code>{{ref|CInt|[c]}}
| {{n/a}}
| rowspan=2| <code>long long int</code> {{ref|a68|[a]}}{{ref|a68g|[g]}}
|-
| colspan=2 align=center|<code>bytes</code> & <code>bits</code>
|-
| [[C (programming language)|C]] ([[C99]] fixed-width)
| rowspan=2| <code>int8_t</code>
| rowspan=2| <code>uint8_t</code>
| rowspan=2| <code>int16_t</code>
| rowspan=2| <code>uint16_t</code>
| rowspan=2| <code>int32_t</code>
| rowspan=2| <code>uint32_t</code>
| rowspan=2| <code>int64_t</code>
| rowspan=2| <code>uint64_t</code>
| rowspan=2| <code>intptr_t</code>{{ref|CInt|[c]}}
| rowspan=2| <code>size_t</code>{{ref|CInt|[c]}}
| rowspan=5 {{n/a}}
|-
| [[C++]] ([[C++11]] fixed-width)
|-
| [[C (programming language)|C]] ([[C99]] variable-width)
| rowspan=2| <code>signed char</code>
| rowspan=2| <code>unsigned char</code>
| rowspan=2| <code>short</code>{{ref|CInt|[c]}}
| rowspan=2| <code>unsigned short</code>{{ref|CInt|[c]}}
| rowspan=2| <code>long</code>{{ref|CInt|[c]}}
| rowspan=2| <code>unsigned long</code>{{ref|CInt|[c]}}
| rowspan=2| <code>long long</code>{{ref|CInt|[c]}}
| rowspan=2| <code>unsigned long long</code>{{ref|CInt|[c]}}
| rowspan=2| <code>int</code>{{ref|CInt|[c]}}
| rowspan=2| <code>unsigned int</code>{{ref|CInt|[c]}}
|-
| [[C++]] ([[C++11]] variable-width)
|-
| [[Objective-C]] ([[Cocoa (API)|Cocoa]])
| <code>signed char''' <br>or<br> '''int8_t</code>
| <code>unsigned char''' <br>or<br> '''uint8_t</code>
| <code>short''' <br>or<br> '''int16_t</code>
| <code>unsigned short''' <br>or<br> '''uint16_t</code>
| <code>int''' <br>or<br> '''int32_t</code>
| <code>unsigned int''' <br>or<br> '''uint32_t</code>
| <code>long long''' <br>or<br> '''int64_t</code>
| <code>unsigned long long''' <br>or<br> '''uint64_t</code>
| <code>NSInteger''' <br>or<br> '''long</code>
| <code>NSUInteger''' <br>or<br> '''unsigned long</code>
|-
| [[C Sharp (programming language)|C#]]
| <code>sbyte</code>
| <code>byte</code>
| rowspan=2| <code>short</code>
| <code>ushort</code>
| rowspan=2| <code>int</code>
| <code>uint</code>
| rowspan=2| <code>long</code>
| <code>ulong</code>
| <code>IntPtr</code>
| <code>UIntPtr</code>
| <code>System.Numerics<wbr/>.BigInteger</code><br />(.NET 4.0)
|-
| [[Java (programming language)|Java]]
| <code>byte</code>
| {{n/a}}
| <code>char</code>{{ref|Java char|[b]}}
| {{n/a}}
| {{n/a}}
| {{n/a}}
| {{n/a}}
| <code>java.math<wbr/>.BigInteger</code>
|-
| [[Go (programming language)|Go]]
| <code>int8</code>
| <code>uint8</code> or <code>byte</code>
| <code>int16</code>
| <code>uint16</code>
| <code>int32</code>
| <code>uint32</code>
| <code>int64</code>
| <code>uint64</code>
| <code>int</code>
| <code>uint</code>
| <code>big.Int</code>
|-
| [[Rust (programming language)|Rust]]
| <code>i8</code>
| <code>u8</code>
| <code>i16</code>
| <code>u16</code>
| <code>i32</code>
| <code>u32</code>
| <code>i64</code>
| <code>u64</code>
| <code>isize</code>
| <code>usize</code>
| {{n/a}}
|-
| [[Swift (programming language)|Swift]]
| <code>Int8</code>
| <code>UInt8</code>
| <code>Int16</code>
| <code>UInt16</code>
| <code>Int32</code>
| <code>UInt32</code>
| <code>Int64</code>
| <code>UInt64</code>
| <code>Int</code>
| <code>UInt</code>
|-
| [[D (programming language)|D]]
| <code>byte</code>
| <code>ubyte</code>
| <code>short</code>
| <code>ushort</code>
| <code>int</code>
| <code>uint</code>
| <code>long</code>
| <code>ulong</code>
|{{n/a}}
|{{n/a}}
| <code>BigInt</code>
|-
| [[Common Lisp]]<ref name=HyperSpec>{{cite web|url=http://www.lispworks.com/documentation/HyperSpec/Front/index.htm|title=Common Lisp HyperSpec (TM)|author=|date=|work=lispworks.com|accessdate=30 January 2017}}</ref>
| <code>(signed-byte 8)</code>
| <code>(unsigned-byte 8)</code>
| <code>(signed-byte 16)</code>
| <code>(unsigned-byte 16)</code>
| <code>(signed-byte 32)</code>
| <code>(unsigned-byte 32)</code>
| <code>(signed-byte 64)</code>
| <code>(unsigned-byte 64)</code>
|
|
| <code>bignum</code>
|-
| [[Scheme (programming language)|Scheme]]
|
|
|
|
|
|
|
|
|
|
|
|-
| [[ISLISP]]<ref name=Specification>{{cite web|url=http://www.islisp.info/specification.html|title=www.islisp.info: Specification|author=|date=|work=islisp.info|accessdate=30 January 2017|archive-url=https://web.archive.org/web/20160122121427/http://islisp.info/specification.html|archive-date=22 January 2016|url-status=dead}}</ref>
|
|
|
|
|
|
|
|
|
|
| <code>bignum</code>
|-
| [[Pascal (programming language)|Pascal]] ([[Free Pascal|FPC]])
| <code>shortint</code>
| <code>byte</code>
| <code>smallint</code>
| <code>word</code>
| <code>longint</code>
| <code>longword</code>
| <code>int64</code>
| <code>qword</code>
| <code>integer</code>
| <code>cardinal</code>
| {{n/a}}
|-
| [[Visual Basic]]
| {{n/a}}
| rowspan=2|<code>Byte</code>
| <code>Integer</code>
| {{n/a}}
| <code>Long</code>
| {{n/a}}
| colspan=2 {{n/a}}
| rowspan=2 colspan=2 {{n/a}}
| rowspan=1 {{n/a}}
|-
| [[Visual Basic .NET]]
| <code>SByte</code>
| <code>Short</code>
| <code>UShort</code>
| <code>Integer</code>
| <code>UInteger</code>
| <code>Long</code>
| <code>ULong</code>
| <code>System.Numerics<wbr/>.BigInteger</code><br />(.NET 4.0)
|-
| [[FreeBasic]]
| <code>Byte</code> or <code>Integer<8></code>
| <code>UByte</code> or <code>UInteger<8></code>
| <code>Short</code> or <code>Integer<16></code>
| <code>UShort</code> or <code>UInteger<16></code>
| <code>Long</code> or <code>Integer<32></code>
| <code>ULong</code> or <code>UInteger<32></code>
| <code>LongInt</code> or <code>Integer<64></code>
| <code>ULongInt</code> or <code>UInteger<64></code>
| <code>Integer</code>
| <code>UInteger</code>
| {{n/a}}
|-
| [[Python (programming language)|Python]] 2.x
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| <code>int</code>
| {{n/a}}
| <code>long</code>
|-
| Python 3.x
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| <code>int</code>
|-
| [[S-Lang (programming language)|S-Lang]]
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| {{n/a}}
|-
| [[Fortran]]
| <code>INTEGER<wbr/>(KIND = n)</code>{{ref|Kinds|[f]}}
| {{n/a}}
| <code>INTEGER<wbr/>(KIND = n)</code>{{ref|Kinds|[f]}}
| {{n/a}}
| <code>INTEGER<wbr/>(KIND = n)</code>{{ref|Kinds|[f]}}
| {{n/a}}
| <code>INTEGER<wbr/>(KIND = n)</code>{{ref|Kinds|[f]}}
| {{n/a}}
|
|
|
|-
| [[PHP]]
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| <code>int</code> {{ref|PHP 32/64 bit long|[m]}}
| {{n/a}}
| <code>int</code> {{ref|PHP 32/64 bit long|[m]}}
| {{n/a}}
| colspan=2 {{n/a}}
| {{ref|PHP bignum|[e]}}
|-
| [[Perl]] 5
| colspan=2 {{n/a}}{{ref|scalars|[d]}}
| colspan=2 {{n/a}}{{ref|scalars|[d]}}
| colspan=2 {{n/a}}{{ref|scalars|[d]}}
| colspan=2 {{n/a}}{{ref|scalars|[d]}}
| colspan=2 {{n/a}}{{ref|scalars|[d]}}
| <code>Math::BigInt</code>
|-
| [[Raku (programming language)|Raku]]
| <code>int8</code>
| <code>uint8</code>
| <code>int16</code>
| <code>uint16</code>
| <code>int32</code>
| <code>uint32</code>
| <code>int64</code>
| <code>uint64</code>
| <code>Int</code>
| colspan=2 {{n/a}}
|-
| [[Ruby (programming language)|Ruby]]
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| <code>Fixnum</code>
| {{n/a}}
| <code>Bignum</code>
|-
| [[Erlang (programming language)|Erlang]]{{ref|Erlang_int|[n]}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| integer()
| {{n/a}}
| integer(){{ref|Erlang_arb|[o]}}
|-
| [[Scala (programming language)|Scala]]
| <code>Byte</code>
| {{n/a}}
| <code>Short</code>
| <code>Char</code>{{ref|Scala Char|[l]}}
| <code>Int</code>
| {{n/a}}
| <code>Long</code>
| {{n/a}}
| {{n/a}}
| {{n/a}}
| <code>scala.math.BigInt</code>
|-
| [[Seed7]]
| {{n/a}}
| {{n/a}}
| {{n/a}}
| {{n/a}}
| {{n/a}}
| {{n/a}}
| <code>integer</code>
| {{n/a}}
| {{n/a}}
| {{n/a}}
| <code>bigInteger</code>
|-
| [[Smalltalk]]
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| <code>SmallInteger</code>{{ref|Smalltalk|[i]}}
| {{n/a}}
| <code>LargeInteger</code>{{ref|Smalltalk|[i]}}
|-
| [[Windows PowerShell]]
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| {{n/a}}
|-
| [[OCaml]]
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| <code>int32</code>
| {{n/a}}
| rowspan=2| <code>int64</code>
| {{n/a}}
| <code>int''' <br/> or <br/> '''nativeint</code>
|
| <code>open Big_int;; <br/> big_int</code>
|-
| [[F Sharp (programming language)|F#]]
| <code>sbyte</code>
| <code>byte</code>
| <code>int16</code>
| <code>uint16</code>
| <code>int32</code> or <code>int</code>
| <code>uint32</code>
| <code>uint64</code>
| <code>nativeint</code>
| <code>unativeint</code>
| <code>bigint</code>
|-
| [[Standard ML]]
| {{n/a}}
| <code>Word8.word</code>
| colspan=2 {{n/a}}
| <code>Int32.int</code>
| <code>Word32.word</code>
| <code>Int64.int</code>
| <code>Word64.word</code>
| <code>int</code>
| <code>word</code>
| <code>LargeInt.int</code> or <br /> <code>IntInf.int</code>
|-
| [[Haskell (programming language)|Haskell]] ([[Glasgow Haskell Compiler|GHC]])
| «<code>import Int</code>» <br /> <code>Int8</code>
| «<code>import Word</code>» <br /> <code>Word8</code>
| «<code>import Int</code>» <br /> <code>Int16</code>
| «<code>import Word</code>» <br /> <code>Word16</code>
| «<code>import Int</code>» <br /> <code>Int32</code>
| «<code>import Word</code>» <br /> <code>Word32</code>
| «<code>import Int</code>» <br /> <code>Int64</code>
| «<code>import Word</code>» <br /> <code>Word64</code>
| <code>Int</code>
| «<code>import Word</code>» <br /> <code>Word</code>
| <code>Integer</code>
|-
| [[Eiffel (programming language)|Eiffel]]
| <code>INTEGER_8</code>
| <code>NATURAL_8</code>
| <code>INTEGER_16</code>
| <code>NATURAL_16</code>
| <code>INTEGER_32</code>
| <code>NATURAL_32</code>
| <code>INTEGER_64</code>
| <code>NATURAL_64</code>
| <code>INTEGER</code>
| <code>NATURAL</code>
| {{n/a}}
|-
| [[COBOL]]{{ref|Cobol|[h]}}
| <code>BINARY-CHAR «SIGNED»</code>
| <code>BINARY-CHAR UNSIGNED</code>
| <code>BINARY-SHORT «SIGNED»</code>
| <code>BINARY-SHORT UNSIGNED</code>
| <code>BINARY-LONG «SIGNED»</code>
| <code>BINARY-LONG UNSIGNED</code>
| <code>BINARY-DOUBLE «SIGNED»</code>
| <code>BINARY-DOUBLE UNSIGNED</code>
| {{n/a}}
| {{n/a}}
| {{n/a}}
|-
| [[Mathematica]]
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| <code>Integer</code>
|-
| [[Wolfram Language]]
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| <code>Integer</code>
|}
{{note|a68|a}} The <u>standard</u> constants <code>int shorts</code> and <code>int lengths</code> can be used to determine how many '<code>short</code>'s and '<code>long</code>'s can be usefully prefixed to '<code>short int</code>' and '<code>long int</code>'. The actually size of the '<code>short int</code>', '<code>int</code>' and '<code>long int</code>' is available as constants <code>short max int</code>, <code>max int</code> and <code>long max int</code> etc.<br />{{note|Java char|b}} Commonly used for characters.<br />{{note|CInt|c}} The ALGOL 68, C and C++ languages do not specify the exact width of the integer types <code>short</code>, <code>int</code>, <code>long</code>, and (C99, C++11) <code>long long</code>, so they are implementation-dependent. In C and C++ <code>short</code>, <code>long</code>, and <code>long long</code> types are required to be at least 16, 32, and 64 bits wide, respectively, but can be more. The <code>int</code> type is required to be at least as wide as <code>short</code> and at most as wide as <code>long</code>, and is typically the width of the word size on the processor of the machine (i.e. on a 32-bit machine it is often 32 bits wide; on 64-bit machines it is sometimes 64 bits wide). C99 and C++11{{citation needed|date=December 2011}} also define the <code>[u]intN_t</code> exact-width types in the [[stdint.h]] header. See[[C syntax#Integral types]] for more information. In addition the types <code>size_t</code> and <code>ptrdiff_t</code> are defined in relation to the address size to hold unsigned and signed integeres sufficiently large to handle array indices and the difference between pointers.<br />{{note|scalars|d}} Perl 5 does not have distinct types. Integers, floating point numbers, strings, etc. are all considered "scalars".<br />{{note|PHP bignum|e}} PHP has two arbitrary-precision libraries. The BCMath library just uses strings as datatype. The GMP library uses an internal "resource" type.<br />{{note|Kinds|f}} The value of "n" is provided by the <code>SELECTED_INT_KIND</code><ref name="fortranwiki.org">{{cite web|url=http://fortranwiki.org/fortran/show/selected_int_kind|title=selected_int_kind in Fortran Wiki|author=|date=|work=fortranwiki.org|accessdate=30 January 2017}}</ref> intrinsic function.<br />{{note|a68g|g}} [[ALGOL 68]]G's run time option ''<code>--precision "number"</code>'' can set precision for <code>long long int</code>s to the required "number" significant digits. The <u>standard</u> constants ''<code>long long int width</code>'' and ''<code>long long max int</code>'' can be used to determine actual precision.<br />{{note|Cobol|h}} [[COBOL]] allows the specification of a required precision and will automatically select an available type capable of representing the specified precision. "<code>PIC S9999</code>", for example, would require a signed variable of four decimal digits precision. If specified as a binary field, this would select a 16-bit signed type on most platforms.<br />{{note|Smalltalk|i}} [[Smalltalk]] automatically chooses an appropriate representation for integral numbers. Typically, two representations are present, one for integers fitting the native word size minus any tag bit (SmallInteger) and one supporting arbitrary sized integers (LargeInteger). Arithmetic operations support polymorphic arguments and return the result in the most appropriate compact representation.<br />{{note|Ada_range|j}} [[Ada (programming language)|Ada]] range types are checked for boundary violations at run-time (as well as at compile-time for static expressions). Run-time boundary violations raise a "constraint error" exception. Ranges are not restricted to powers of two. Commonly predefined Integer subtypes are: Positive (<code>range 1 .. Integer'Last</code>) and Natural (<code>range 0 .. Integer'Last</code>). <code>Short_Short_Integer</code> (8 bits), <code>Short_Integer</code> (16 bits) and <code>Long_Integer</code> (64 bits) are also commonly predefined, but not required by the Ada standard. Run time checks can be disabled if performance is more important than integrity checks.<br />{{note|Ada_mod|k}} [[Ada (programming language)|Ada]] modulo types implement modulo arithmetic in all operations, i.e. no range violations are possible. Modulos are not restricted to powers of two.
<br />{{note|Scala char|l}} Commonly used for characters like Java's char.<br />{{note|PHP 32/64 bit long|m}} <code>int</code> in PHP has the same width as <code>long</code> type in C has on that system {{ref|CInt|[c]}}.<br />{{note|Erlang_int|n}} [[Erlang (programming language)|Erlang]] is dynamically typed. The type identifiers are usually used to specify types of record fields and the argument and return types of functions.<ref>{{cite web|url=http://www.erlang.org/doc/reference_manual/typespec.html|title=Erlang -- Types and Function Specifications|author=|date=|work=erlang.org|accessdate=30 January 2017}}</ref><br />{{note|Erlang_arb|o}} When it exceeds one word.<ref>{{cite web|url=http://www.erlang.org/doc/efficiency_guide/advanced.html|title=Erlang -- Advanced|author=|date=|work=erlang.org|accessdate=30 January 2017}}</ref>
Line 491 ⟶ 23:
! Processor dependent
|-
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012">Ada Reference Manual – Language and Standard Libraries; ISO/IEC 8652:201x (E), {{cite web|title=Reference Manual|url=http://www.ada-auth.org/standards/12rm/RM-Final.pdf|url-status=dead|archiveurl=https://web.archive.org/web/20110427190723/http://www.ada-auth.org/standards/12rm/RM-Final.pdf|archivedate=2011-04-27|accessdate=2013-07-19}}</ref>
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| <code>Float</code>
| <code>Long_Float</code>