Sideway
output.to from Sideway
`-=[]โŸจโŸฉ\;',./~!@#$%^&*()_+{}|:"<>? ๐‘Ž๐‘๐‘๐‘‘๐‘’๐‘“๐‘”โ„Ž๐‘–๐‘—๐‘˜๐‘™๐‘š๐‘›๐‘œ๐‘๐‘ž๐‘Ÿ๐‘ ๐‘ก๐‘ข๐‘ฃ๐‘ค๐‘ฅ๐‘ฆ๐‘ง ร…โ€‰โˆ’โ€‚ร—โ€ƒโ‹…โˆ“ยฑโˆ˜๊žŠ๏นฆโˆ—โˆ™ โ„ฏ ๐”ธ๐”นโ„‚๐”ป๐”ผ๐”ฝ๐”พโ„๐•€๐•๐•‚๐•ƒ๐•„โ„•๐•†โ„™โ„šโ„๐•Š๐•‹๐•Œ๐•๐•Ž๐•๐•โ„ค๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐‘€๐‘๐‘‚๐‘ƒ๐‘„๐‘…๐‘†๐‘‡๐‘ˆ๐‘‰๐‘Š๐‘‹๐‘Œ๐‘ โˆผโˆฝโˆพโ‰โ‰‚โ‰ƒโ‰„โ‰…โ‰†โ‰‡โ‰ˆโ‰‰โ‰Œโ‰โ‰ โ‰ก โ‰คโ‰ฅโ‰ฆโ‰งโ‰จโ‰ฉโ‰ชโ‰ซ โˆˆโˆ‰โˆŠโˆ‹โˆŒโˆ โŠ‚โŠƒโŠ„โŠ…โІโЇ ๐›ผ๐›ฝ๐›พ๐›ฟ๐œ€๐œ๐œ‚๐œƒ๐œ„๐œ…๐œ†๐œ‡๐œˆ๐œ‰๐œŠ๐œ‹๐œŒ๐œŽ๐œ๐œ๐œ‘๐œ’๐œ“๐œ” โˆ€โˆ‚โˆƒโˆ…โฆฐโˆ†โˆ‡โˆŽโˆžโˆโˆดโˆต โˆโˆโˆ‘โ‹€โ‹โ‹‚โ‹ƒ โˆงโˆจโˆฉโˆช โˆซโˆฌโˆญโˆฎโˆฏโˆฐโˆฑโˆฒโˆณ โˆฅโ‹ฎโ‹ฏโ‹ฐโ‹ฑ โ€– โ€ฒ โ€ณ โ€ด โ„ โ— สน สบ โ€ต โ€ถ โ€ท ๏น ๏น‚ ๏นƒ ๏น„ ๏ธน ๏ธบ ๏ธป ๏ธผ ๏ธ— ๏ธ˜ ๏ธฟ ๏น€ ๏ธฝ ๏ธพ ๏น‡ ๏นˆ ๏ธท ๏ธธ โœ   โ   โŽด  โŽต  โž   โŸ   โ    โก โ†โ†‘โ†’โ†“โ†คโ†ฆโ†ฅโ†งโ†”โ†•โ†–โ†—โ†˜โ†™โ–ฒโ–ผโ—€โ–ถโ†บโ†ปโŸฒโŸณ โ†ผโ†ฝโ†พโ†ฟโ‡€โ‡โ‡‚โ‡ƒโ‡„โ‡…โ‡†โ‡‡ โ‡โ‡‘โ‡’โ‡“โ‡”โ‡Œโ‡โ‡โ‡•โ‡–โ‡—โ‡˜โ‡™โ‡™โ‡ณโฅขโฅฃโฅคโฅฅโฅฆโฅงโฅจโฅฉโฅชโฅซโฅฌโฅญโฅฎโฅฏ
Draft for Information Only

Content

Numeric Types
โ€ƒTypes of Python Numeric
โ€ƒโ€ƒInteger
โ€ƒโ€ƒFloating Point Number
โ€ƒโ€ƒComplex Number
โ€ƒPython Numeric Operations
โ€ƒโ€ƒArithmetic Operations
โ€ƒโ€ƒReal Number Operations
โ€ƒTypical Integer Operations
โ€ƒโ€ƒBitwise Operations on Integer Types
โ€ƒโ€ƒโ€ƒTypes of Bitwise Operators
โ€ƒโ€ƒMethods on Integer Types
โ€ƒTypical Float Operations
โ€ƒโ€ƒMethods on Float Types
โ€ƒHashing of numeric types
โ€ƒSource and Reference

Numeric Types

The Python numeric types are integers, floating point numbers, and complex numbers. Besides, booleans are implemented as a subtype of integers.

Types of Python Numeric

Integer

Integers int have unlimited precision. The constructor int() can be used to create a integer. Integer literals can also be used to create integers. For example,
  • Decimal integer decinteger:e.g. 1234567890
  • Binary integer bininteger:e.g. 0๐‘10,0๐ต10
  • Octal integer octinteger:e.g. 0๐‘œ1234567, 0๐‘‚1234567
  • Hexadecimal integer hexinteger: e.g. 0๐‘ฅ1234567890๐ด๐ต๐ถ๐ท๐ธ๐น, 0๐‘‹1234567890๐ด๐ต๐ถ๐ท๐ธ๐น

Floating Point Number

Floating point numbers are usually implemented using double in C. Information about the precision and internal representation of Python floating point numbers can be obtained in sys.float_info. The standard library also includes the additional numeric types fractions.Fraction for rationals, and decimal.Decimal for floating-point numbers with user-definable precision. The constructor float() can also be used to create a integer. Floating point literals can also be used to create floating point number. For example,
  • Decimal point floating point number: pointfloat e.g. 123456.7890
  • Exponent floating point number: exponentfloat e.g. 7๐‘’10,7.2๐ธ10

Complex Number

Complex numbers have a real and imaginary part. The real part of a complex number can be extracted by ๐‘ง.real and the imaginary part of the complex number can be extracted by ๐‘ง.imag. The constructor complex() can be used to create a integer. The real part of a complex number can be created by the floating point numeral or integer numeral. While the imaginary part of the complex number can be created by the imaginary numeral which is similar to the real part but a specifier ๐‘— or ๐ฝ is appended to the numeric literal. A complex number with a zero real part can be created by a imaginary literal only. For example, 1.3+0.8๐‘—, 5.6+8.4๐ฝ

Python Numeric Operations

Python numeric operations can be divided into basic arithmetic operations and real operations.

Arithmetic Operations

The basic types of Python supported operators for basic arithmetic operations are Unary operators, binary operators and numeric functions. OperationDescriptionRemarks -๐‘ฅ๐‘ฅ negated +๐‘ฅ๐‘ฅ unchanged ๐‘ฅ+๐‘ฆsum of ๐‘ฅ and ๐‘ฆ ๐‘ฅ-๐‘ฆdifference of ๐‘ฅ and ๐‘ฆ ๐‘ฅ*๐‘ฆproduct of ๐‘ฅ and ๐‘ฆ ๐‘ฅ/๐‘ฆquotient of ๐‘ฅ and ๐‘ฆ ๐‘ฅ//๐‘ฆfloored quotient of ๐‘ฅ and ๐‘ฆ ๐‘ฅ%๐‘ฆremainder of ๐‘ฅ/๐‘ฆ abs(๐‘ฅ)absolute value or magnitude of ๐‘ฅ int(๐‘ฅ)๐‘ฅ converted to integer float(๐‘ฅ)๐‘ฅ converted to floating point complex(๐‘Ÿ๐‘’,๐‘–๐‘š)a complex number with real part ๐‘Ÿ๐‘’, imaginary part ๐‘–๐‘š with ๐‘–๐‘š defaults to zero ๐‘.conjugate()conjugate of the complex number ๐‘ divmod(๐‘ฅ,๐‘ฆ)the pair (๐‘ฅ//๐‘ฆ,๐‘ฅ%๐‘ฆ) pow(๐‘ฅ,๐‘ฆ)๐‘ฅ to the power ๐‘ฆ ๐‘ฅ**๐‘ฆ๐‘ฅ to the power ๐‘ฆ
Also referred to as integer division. The resultant value is a whole integer, though the resultโ€™s type is not necessarily int. The result is always rounded towards minus infinity: 1//2 is 0, (-1)//2 is -1, 1//(-2) is -1, and (-1)//(-2) is 0.

Not for complex numbers. Instead convert to floats using abs() if appropriate.

Conversion from floating point to integer may round or truncate as in C; see functions math.floor() and math.ceil() for well-defined conversions.

float also accepts the strings โ€œnanโ€ and โ€œinfโ€ with an optional prefix โ€œ+โ€ or โ€œ-โ€ for Not a Number (NaN) and positive or negative infinity.

Python defines pow(0, 0) and 0 ** 0 to be 1, as is common for programming languages.

The numeric literals accepted include the digits 0 to 9 or any Unicode equivalent (code points with the Nd property).

Real Number Operations

The standard types of Python supported operators for real number operations are numeric functions. OperationDescriptionRemarks math.trunc(๐‘ฅ)๐‘ฅ truncated to Integral round(๐‘ฅ[,๐‘›])๐‘ฅ rounded to ๐‘› digits, rounding half to even. Default to 0, if ๐‘› is omitted math.floor(๐‘ฅ)the greatest Integral ๐‘ฅ <= math.ceil(๐‘ฅ)the least Integral ๐‘ฅ >=

Typical Integer Operations

Bitwise Operations on Integer Types

Bitwise operations are for integers only. The basic types of Python supported operators are Unary operators, binary operators and numeric functions.

Types of Bitwise Operators

The types of bitwise operators are: OperationDescriptionRemarks ~๐‘ฅthe bits of ๐‘ฅ ๐‘ฅ|๐‘ฆbitwise or of ๐‘ฅ and ๐‘ฆ ๐‘ฅ^๐‘ฆbitwise exclusive or of ๐‘ฅ and ๐‘ฆ ๐‘ฅ&๐‘ฆbitwise and of ๐‘ฅ and ๐‘ฆ ๐‘ฅ<<๐‘›๐‘ฅ shifted left by ๐‘› bits ๐‘ฅ>>๐‘›๐‘ฅ shifted right by ๐‘› bits
The result of bitwise operations is calculated as though carried out in twoโ€™s complement with an infinite number of sign bits.

The priorities of the binary bitwise operations are all lower than the numeric operations and higher than the comparisons; the unary operation ~ has the same priority as the other unary numeric operations (+ and -).


    Negative shift counts are illegal and cause a ValueError to be raised.

    A left shift by n bits is equivalent to multiplication by pow(2, n) without overflow check.

    A right shift by n bits is equivalent to division by pow(2, n) without overflow check.

    Performing these calculations with at least one extra sign extension bit in a finite twoโ€™s complement representation (a working bit-width of 1 + max(x.bit_length(), y.bit_length()) or more) is sufficient to get the same result as if there were an infinite number of sign bits.
         

Methods on Integer Types

The int type implements the numbers.Integral abstract base class. Other Methods on integer are: OperationDescriptionRemarks int.bit_length() int.to_bytes(length, byteorder, *, signed=False) classmethod int.from_bytes(bytes, byteorder, *, signed=False) int.as_integer_ratio()

Typical Float Operations

The float type implements the numbers.Real abstract base class.

Methods on Float Types

Other Methods on float are: OperationDescriptionRemarks float.as_integer_ratio() float.is_integer() float.hex() classmethod float.fromhex(s)

Hashing of numeric types

For numbers x and y, possibly of different types, itโ€™s a requirement that hash(x) == hash(y) whenever x == y (see the __hash__() method documentation for more details). For ease of implementation and efficiency across a variety of numeric types (including int, float, decimal.Decimal and fractions.Fraction) Pythonโ€™s hash for numeric types is based on a single mathematical function thatโ€™s defined for any rational number, and hence applies to all instances of int and fractions.Fraction, and all finite instances of float and decimal.Decimal. Essentially, this function is given by reduction modulo P for a fixed prime P. The value of P is made available to Python as the modulus attribute of sys.hash_info.

CPython implementation detail: Currently, the prime used is P = 2**31 - 1 on machines with 32-bit C longs and P = 2**61 - 1 on machines with 64-bit C longs.

Here are the rules in detail:

    If x = m / n is a nonnegative rational number and n is not divisible by P, define hash(x) as m * invmod(n, P) % P, where invmod(n, P) gives the inverse of n modulo P.

    If x = m / n is a nonnegative rational number and n is divisible by P (but m is not) then n has no inverse modulo P and the rule above doesnโ€™t apply; in this case define hash(x) to be the constant value sys.hash_info.inf.

    If x = m / n is a negative rational number define hash(x) as -hash(-x). If the resulting hash is -1, replace it with -2.

    The particular values sys.hash_info.inf, -sys.hash_info.inf and sys.hash_info.nan are used as hash values for positive infinity, negative infinity, or nans (respectively). (All hashable nans have the same hash value.)

    For a complex number z, the hash values of the real and imaginary parts are combined by computing hash(z.real) + sys.hash_info.imag * hash(z.imag), reduced modulo 2**sys.hash_info.width so that it lies in range(-2**(sys.hash_info.width - 1), 2**(sys.hash_info.width - 1)). Again, if the result is -1, itโ€™s replaced with -2.

Source and Reference


ยฉsideway

ID: 201002402 Last Updated: 10/24/2020 Revision: 0


Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 9

Culture

Chinese 1097

English 339

Travel 38

Reference 79

Hardware 55

Computer

Hardware 259

Software

Application 213

Digitization 37

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 290new

Unicode 504

HTML 66new

Common Color 1new

Html Entity (Unicode) 1new

Html 401 Special 1

CSS 65new

Selector 1

SVG 46

ASP.NET 270

OS 447new

MS Windows

Windows10 1new

.NET Framework 1

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Set 1

Logic 1

Algebra 84

Number Theory 207new

Trigonometry 31

Geometry 34

Coordinate Geometry 2

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2026 Sideway . All rights reserved Disclaimers last modified on 06 September 2019