Sophie

Sophie

distrib > Fedora > 20 > x86_64 > by-pkgid > d9f573299e87e886807be879704f0b6e > files > 128

julia-doc-0.3.4-1.fc20.noarch.rpm




<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Integers and Floating-Point Numbers &mdash; Julia Language 0.3.4 documentation</title>
  

  
  

  
  <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>

  
  
    

  

  
  
    <link rel="stylesheet" href="../_static/julia.css" type="text/css" />
  

  
    <link rel="stylesheet" href="../_static/julia.css" type="text/css" />
  
    <link rel="top" title="Julia Language 0.3.4 documentation" href="../index.html"/>
        <link rel="next" title="Mathematical Operations and Elementary Functions" href="mathematical-operations.html"/>
        <link rel="prev" title="Variables" href="variables.html"/> 

  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-nav-search">
        <a href="http://julialang.org/"><img src="../_static/julia-logo.svg" class="logo"></a>
        <!--
        <a href="../index.html" class="fa fa-home"> Julia Language</a>
        -->
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
        
        
            <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="getting-started.html">Getting Started</a><ul>
<li class="toctree-l2"><a class="reference internal" href="getting-started.html#resources">Resources</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="variables.html">Variables</a><ul>
<li class="toctree-l2"><a class="reference internal" href="variables.html#allowed-variable-names">Allowed Variable Names</a></li>
<li class="toctree-l2"><a class="reference internal" href="variables.html#stylistic-conventions">Stylistic Conventions</a></li>
</ul>
</li>
<li class="toctree-l1 current"><a class="current reference internal" href="">Integers and Floating-Point Numbers</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#integers">Integers</a></li>
<li class="toctree-l2"><a class="reference internal" href="#floating-point-numbers">Floating-Point Numbers</a></li>
<li class="toctree-l2"><a class="reference internal" href="#arbitrary-precision-arithmetic">Arbitrary Precision Arithmetic</a></li>
<li class="toctree-l2"><a class="reference internal" href="#numeric-literal-coefficients">Numeric Literal Coefficients</a></li>
<li class="toctree-l2"><a class="reference internal" href="#literal-zero-and-one">Literal zero and one</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="mathematical-operations.html">Mathematical Operations and Elementary Functions</a><ul>
<li class="toctree-l2"><a class="reference internal" href="mathematical-operations.html#arithmetic-operators">Arithmetic Operators</a></li>
<li class="toctree-l2"><a class="reference internal" href="mathematical-operations.html#bitwise-operators">Bitwise Operators</a></li>
<li class="toctree-l2"><a class="reference internal" href="mathematical-operations.html#updating-operators">Updating operators</a></li>
<li class="toctree-l2"><a class="reference internal" href="mathematical-operations.html#numeric-comparisons">Numeric Comparisons</a></li>
<li class="toctree-l2"><a class="reference internal" href="mathematical-operations.html#elementary-functions">Elementary Functions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="complex-and-rational-numbers.html">Complex and Rational Numbers</a><ul>
<li class="toctree-l2"><a class="reference internal" href="complex-and-rational-numbers.html#complex-numbers">Complex Numbers</a></li>
<li class="toctree-l2"><a class="reference internal" href="complex-and-rational-numbers.html#rational-numbers">Rational Numbers</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="strings.html">Strings</a><ul>
<li class="toctree-l2"><a class="reference internal" href="strings.html#characters">Characters</a></li>
<li class="toctree-l2"><a class="reference internal" href="strings.html#string-basics">String Basics</a></li>
<li class="toctree-l2"><a class="reference internal" href="strings.html#unicode-and-utf-8">Unicode and UTF-8</a></li>
<li class="toctree-l2"><a class="reference internal" href="strings.html#interpolation">Interpolation</a></li>
<li class="toctree-l2"><a class="reference internal" href="strings.html#common-operations">Common Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="strings.html#non-standard-string-literals">Non-Standard String Literals</a></li>
<li class="toctree-l2"><a class="reference internal" href="strings.html#regular-expressions">Regular Expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="strings.html#id3">Byte Array Literals</a></li>
<li class="toctree-l2"><a class="reference internal" href="strings.html#version-number-literals">Version Number Literals</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="functions.html">Functions</a><ul>
<li class="toctree-l2"><a class="reference internal" href="functions.html#argument-passing-behavior">Argument Passing Behavior</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#the-return-keyword">The <tt class="docutils literal"><span class="pre">return</span></tt> Keyword</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#id1">Operators Are Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#operators-with-special-names">Operators With Special Names</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#anonymous-functions">Anonymous Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#multiple-return-values">Multiple Return Values</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#varargs-functions">Varargs Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#optional-arguments">Optional Arguments</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#keyword-arguments">Keyword Arguments</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#evaluation-scope-of-default-values">Evaluation Scope of Default Values</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#block-syntax-for-function-arguments">Block Syntax for Function Arguments</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#further-reading">Further Reading</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="control-flow.html">Control Flow</a><ul>
<li class="toctree-l2"><a class="reference internal" href="control-flow.html#compound-expressions">Compound Expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="control-flow.html#conditional-evaluation">Conditional Evaluation</a></li>
<li class="toctree-l2"><a class="reference internal" href="control-flow.html#short-circuit-evaluation">Short-Circuit Evaluation</a></li>
<li class="toctree-l2"><a class="reference internal" href="control-flow.html#repeated-evaluation-loops">Repeated Evaluation: Loops</a></li>
<li class="toctree-l2"><a class="reference internal" href="control-flow.html#exception-handling">Exception Handling</a></li>
<li class="toctree-l2"><a class="reference internal" href="control-flow.html#tasks-aka-coroutines">Tasks (aka Coroutines)</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="variables-and-scoping.html">Scope of Variables</a><ul>
<li class="toctree-l2"><a class="reference internal" href="variables-and-scoping.html#for-loops-and-comprehensions">For Loops and Comprehensions</a></li>
<li class="toctree-l2"><a class="reference internal" href="variables-and-scoping.html#constants">Constants</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="types.html">Types</a><ul>
<li class="toctree-l2"><a class="reference internal" href="types.html#type-declarations">Type Declarations</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#abstract-types">Abstract Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#bits-types">Bits Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#composite-types">Composite Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#immutable-composite-types">Immutable Composite Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#declared-types">Declared Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#tuple-types">Tuple Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#type-unions">Type Unions</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#man-parametric-types">Parametric Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#type-aliases">Type Aliases</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#operations-on-types">Operations on Types</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="methods.html">Methods</a><ul>
<li class="toctree-l2"><a class="reference internal" href="methods.html#defining-methods">Defining Methods</a></li>
<li class="toctree-l2"><a class="reference internal" href="methods.html#method-ambiguities">Method Ambiguities</a></li>
<li class="toctree-l2"><a class="reference internal" href="methods.html#parametric-methods">Parametric Methods</a></li>
<li class="toctree-l2"><a class="reference internal" href="methods.html#note-on-optional-and-keyword-arguments">Note on Optional and keyword Arguments</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="constructors.html">Constructors</a><ul>
<li class="toctree-l2"><a class="reference internal" href="constructors.html#outer-constructor-methods">Outer Constructor Methods</a></li>
<li class="toctree-l2"><a class="reference internal" href="constructors.html#inner-constructor-methods">Inner Constructor Methods</a></li>
<li class="toctree-l2"><a class="reference internal" href="constructors.html#incomplete-initialization">Incomplete Initialization</a></li>
<li class="toctree-l2"><a class="reference internal" href="constructors.html#parametric-constructors">Parametric Constructors</a></li>
<li class="toctree-l2"><a class="reference internal" href="constructors.html#case-study-rational">Case Study: Rational</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="conversion-and-promotion.html">Conversion and Promotion</a><ul>
<li class="toctree-l2"><a class="reference internal" href="conversion-and-promotion.html#conversion">Conversion</a></li>
<li class="toctree-l2"><a class="reference internal" href="conversion-and-promotion.html#promotion">Promotion</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="modules.html">Modules</a><ul>
<li class="toctree-l2"><a class="reference internal" href="modules.html#summary-of-module-usage">Summary of module usage</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="metaprogramming.html">Metaprogramming</a><ul>
<li class="toctree-l2"><a class="reference internal" href="metaprogramming.html#expressions-and-eval">Expressions and Eval</a></li>
<li class="toctree-l2"><a class="reference internal" href="metaprogramming.html#macros">Macros</a></li>
<li class="toctree-l2"><a class="reference internal" href="metaprogramming.html#reflection">Reflection</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="arrays.html">Multi-dimensional Arrays</a><ul>
<li class="toctree-l2"><a class="reference internal" href="arrays.html#arrays">Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="arrays.html#sparse-matrices">Sparse Matrices</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="linear-algebra.html">Linear algebra</a><ul>
<li class="toctree-l2"><a class="reference internal" href="linear-algebra.html#matrix-factorizations">Matrix factorizations</a></li>
<li class="toctree-l2"><a class="reference internal" href="linear-algebra.html#special-matrices">Special matrices</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="networking-and-streams.html">Networking and Streams</a><ul>
<li class="toctree-l2"><a class="reference internal" href="networking-and-streams.html#basic-stream-i-o">Basic Stream I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="networking-and-streams.html#text-i-o">Text I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="networking-and-streams.html#working-with-files">Working with Files</a></li>
<li class="toctree-l2"><a class="reference internal" href="networking-and-streams.html#a-simple-tcp-example">A simple TCP example</a></li>
<li class="toctree-l2"><a class="reference internal" href="networking-and-streams.html#resolving-ip-addresses">Resolving IP Addresses</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="parallel-computing.html">Parallel Computing</a><ul>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#data-movement">Data Movement</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#parallel-map-and-loops">Parallel Map and Loops</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#synchronization-with-remote-references">Synchronization With Remote References</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#scheduling">Scheduling</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#distributed-arrays">Distributed Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#constructing-distributed-arrays">Constructing Distributed Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#distributed-array-operations">Distributed Array Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#shared-arrays-experimental">Shared Arrays (Experimental)</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#clustermanagers">ClusterManagers</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="running-external-programs.html">Running External Programs</a><ul>
<li class="toctree-l2"><a class="reference internal" href="running-external-programs.html#interpolation">Interpolation</a></li>
<li class="toctree-l2"><a class="reference internal" href="running-external-programs.html#quoting">Quoting</a></li>
<li class="toctree-l2"><a class="reference internal" href="running-external-programs.html#pipelines">Pipelines</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="calling-c-and-fortran-code.html">Calling C and Fortran Code</a><ul>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#mapping-c-types-to-julia">Mapping C Types to Julia</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#accessing-data-through-a-pointer">Accessing Data through a Pointer</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#passing-pointers-for-modifying-inputs">Passing Pointers for Modifying Inputs</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#garbage-collection-safety">Garbage Collection Safety</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#non-constant-function-specifications">Non-constant Function Specifications</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#indirect-calls">Indirect Calls</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#calling-convention">Calling Convention</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#accessing-global-variables">Accessing Global Variables</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#passing-julia-callback-functions-to-c">Passing Julia Callback Functions to C</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#c">C++</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#handling-platform-variations">Handling Platform Variations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="interacting-with-julia.html">Interacting With Julia</a><ul>
<li class="toctree-l2"><a class="reference internal" href="interacting-with-julia.html#the-different-prompt-modes">The different prompt modes</a></li>
<li class="toctree-l2"><a class="reference internal" href="interacting-with-julia.html#key-bindings">Key bindings</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="embedding.html">Embedding Julia</a><ul>
<li class="toctree-l2"><a class="reference internal" href="embedding.html#high-level-embedding">High-Level Embedding</a></li>
<li class="toctree-l2"><a class="reference internal" href="embedding.html#converting-types">Converting Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="embedding.html#calling-julia-functions">Calling Julia Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="embedding.html#memory-management">Memory Management</a></li>
<li class="toctree-l2"><a class="reference internal" href="embedding.html#working-with-arrays">Working with Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="embedding.html#exceptions">Exceptions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="packages.html">Packages</a><ul>
<li class="toctree-l2"><a class="reference internal" href="packages.html#package-status">Package Status</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#adding-and-removing-packages">Adding and Removing Packages</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#installing-unregistered-packages">Installing Unregistered Packages</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#updating-packages">Updating Packages</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#checkout-pin-and-free">Checkout, Pin and Free</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="packages.html#package-development">Package Development</a><ul>
<li class="toctree-l2"><a class="reference internal" href="packages.html#initial-setup">Initial Setup</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#generating-a-new-package">Generating a New Package</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#making-your-package-available">Making Your Package Available</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#publishing-your-package">Publishing Your Package</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#tagging-package-versions">Tagging Package Versions</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#fixing-package-requirements">Fixing Package Requirements</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#man-package-requirements">Requirements Specification</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="performance-tips.html">Performance Tips</a><ul>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#avoid-global-variables">Avoid global variables</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#measure-performance-with-time-and-pay-attention-to-memory-allocation">Measure performance with <tt class="docutils literal"><span class="pre">&#64;time</span></tt> and pay attention to memory allocation</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#tools">Tools</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#avoid-containers-with-abstract-type-parameters">Avoid containers with abstract type parameters</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#type-declarations">Type declarations</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#break-functions-into-multiple-definitions">Break functions into multiple definitions</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#write-type-stable-functions">Write &#8220;type-stable&#8221; functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#avoid-changing-the-type-of-a-variable">Avoid changing the type of a variable</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#separate-kernel-functions">Separate kernel functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#access-arrays-in-memory-order-along-columns">Access arrays in memory order, along columns</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#pre-allocating-outputs">Pre-allocating outputs</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#avoid-string-interpolation-for-i-o">Avoid string interpolation for I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#fix-deprecation-warnings">Fix deprecation warnings</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#tweaks">Tweaks</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#performance-annotations">Performance Annotations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="style-guide.html">Style Guide</a><ul>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#write-functions-not-just-scripts">Write functions, not just scripts</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#avoid-writing-overly-specific-types">Avoid writing overly-specific types</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#handle-excess-argument-diversity-in-the-caller">Handle excess argument diversity in the caller</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#append-to-names-of-functions-that-modify-their-arguments">Append <cite>!</cite> to names of functions that modify their arguments</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#avoid-strange-type-unions">Avoid strange type Unions</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#try-to-avoid-nullable-fields">Try to avoid nullable fields</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#avoid-elaborate-container-types">Avoid elaborate container types</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#avoid-underscores-in-names">Avoid underscores in names</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-overuse-try-catch">Don&#8217;t overuse try-catch</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-parenthesize-conditions">Don&#8217;t parenthesize conditions</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-overuse">Don&#8217;t overuse ...</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-use-unnecessary-static-parameters">Don&#8217;t use unnecessary static parameters</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#avoid-confusion-about-whether-something-is-an-instance-or-a-type">Avoid confusion about whether something is an instance or a type</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-overuse-macros">Don&#8217;t overuse macros</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-expose-unsafe-operations-at-the-interface-level">Don&#8217;t expose unsafe operations at the interface level</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-overload-methods-of-base-container-types">Don&#8217;t overload methods of base container types</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#be-careful-with-type-equality">Be careful with type equality</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#do-not-write-x-f-x">Do not write <tt class="docutils literal"><span class="pre">x-&gt;f(x)</span></tt></a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">Frequently Asked Questions</a><ul>
<li class="toctree-l2"><a class="reference internal" href="faq.html#sessions-and-the-repl">Sessions and the REPL</a></li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#functions">Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#types-type-declarations-and-constructors">Types, type declarations, and constructors</a></li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#nothingness-and-missing-values">Nothingness and missing values</a></li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#julia-releases">Julia Releases</a></li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#developing-julia">Developing Julia</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="noteworthy-differences.html">Noteworthy Differences from other Languages</a><ul>
<li class="toctree-l2"><a class="reference internal" href="noteworthy-differences.html#noteworthy-differences-from-matlab">Noteworthy differences from MATLAB</a></li>
<li class="toctree-l2"><a class="reference internal" href="noteworthy-differences.html#noteworthy-differences-from-r">Noteworthy differences from R</a></li>
<li class="toctree-l2"><a class="reference internal" href="noteworthy-differences.html#noteworthy-differences-from-python">Noteworthy differences from Python</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/base.html">The Standard Library</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#introduction">Introduction</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#getting-around">Getting Around</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#all-objects">All Objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#types">Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#generic-functions">Generic Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#syntax">Syntax</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#iteration">Iteration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#general-collections">General Collections</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#iterable-collections">Iterable Collections</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#indexable-collections">Indexable Collections</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#associative-collections">Associative Collections</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#set-like-collections">Set-Like Collections</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#dequeues">Dequeues</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#strings">Strings</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#i-o">I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#network-i-o">Network I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#text-i-o">Text I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#multimedia-i-o">Multimedia I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#memory-mapped-i-o">Memory-mapped I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#standard-numeric-types">Standard Numeric Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#mathematical-operators">Mathematical Operators</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#mathematical-functions">Mathematical Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#data-formats">Data Formats</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#numbers">Numbers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#bigfloats">BigFloats</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#random-numbers">Random Numbers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#arrays">Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#combinatorics">Combinatorics</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#statistics">Statistics</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#signal-processing">Signal Processing</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#numerical-integration">Numerical Integration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#parallel-computing">Parallel Computing</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#distributed-arrays">Distributed Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#shared-arrays-experimental-unix-only-feature">Shared Arrays (Experimental, UNIX-only feature)</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#system">System</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#c-interface">C Interface</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#errors">Errors</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#tasks">Tasks</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#events">Events</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#reflection">Reflection</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#internals">Internals</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/sparse.html">Sparse Matrices</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/linalg.html">Linear Algebra</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/linalg.html#module-Base.LinAlg.BLAS">BLAS Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/constants.html">Constants</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/file.html">Filesystem</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/punctuation.html">Punctuation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/sort.html">Sorting and Related Functions</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/sort.html#sorting-functions">Sorting Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/sort.html#order-related-functions">Order-Related Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/sort.html#sorting-algorithms">Sorting Algorithms</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/pkg.html">Package Manager Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/collections.html">Collections and Data Structures</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/collections.html#priorityqueue">PriorityQueue</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/collections.html#heap-functions">Heap Functions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/graphics.html">Graphics</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/graphics.html#geometry">Geometry</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/test.html">Unit and Functional Testing</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/test.html#overview">Overview</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/test.html#handlers">Handlers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/test.html#macros">Macros</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/test.html#functions">Functions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/test.html#testing-base-julia">Testing Base Julia</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/profile.html">Profiling</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/profile.html#basic-usage">Basic usage</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/profile.html#accumulation-and-clearing">Accumulation and clearing</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/profile.html#options-for-controlling-the-display-of-profile-results">Options for controlling the display of profile results</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/profile.html#configuration">Configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/profile.html#function-reference">Function reference</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../devdocs/julia.html">Documentation of Julia&#8217;s Internals</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../devdocs/cartesian.html">Base.Cartesian</a></li>
<li class="toctree-l2"><a class="reference internal" href="../devdocs/sysimg.html">System Image Building</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../devdocs/C.html">Developing/debugging Julia&#8217;s C code</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../devdocs/backtraces.html">Reporting and analyzing crashes (segfaults)</a></li>
<li class="toctree-l2"><a class="reference internal" href="../devdocs/debuggingtips.html">gdb debugging tips</a></li>
</ul>
</li>
</ul>

        
      </div>
      &nbsp;
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="../index.html">Julia Language</a>
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="../index.html">Docs</a> &raquo;</li>
      
    <li>Integers and Floating-Point Numbers</li>
      <li class="wy-breadcrumbs-aside">
        
          <a href="../_sources/manual/integers-and-floating-point-numbers.txt" rel="nofollow"> View page source</a>
        
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document">
            
  <div class="section" id="integers-and-floating-point-numbers">
<span id="man-integers-and-floating-point-numbers"></span><h1>Integers and Floating-Point Numbers<a class="headerlink" href="#integers-and-floating-point-numbers" title="Permalink to this headline">¶</a></h1>
<p>Integers and floating-point values are the basic building blocks of
arithmetic and computation. Built-in representations of such values are
called numeric primitives, while representations of integers and
floating-point numbers as immediate values in code are known as numeric
literals. For example, <tt class="docutils literal"><span class="pre">1</span></tt> is an integer literal, while <tt class="docutils literal"><span class="pre">1.0</span></tt> is a
floating-point literal; their binary in-memory representations as
objects are numeric primitives.</p>
<p>Julia provides a broad range of primitive numeric types, and a full complement
of arithmetic and bitwise operators as well as standard mathematical functions
are defined over them. These map directly onto numeric types and operations
that are natively supported on modern computers, thus allowing Julia to take
full advantage of computational resources. Additionally, Julia provides
software support for <a class="reference internal" href="#man-arbitrary-precision-arithmetic"><em>Arbitrary Precision Arithmetic</em></a>, which can
handle operations on numeric values that cannot be represented effectively in
native hardware representations, but at the cost of relatively slower
performance.</p>
<p>The following are Julia&#8217;s primitive numeric types:</p>
<ul class="simple">
<li><strong>Integer types:</strong></li>
</ul>
<table border="1" class="docutils">
<colgroup>
<col width="17%" />
<col width="11%" />
<col width="22%" />
<col width="22%" />
<col width="28%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td>Type</td>
<td>Signed?</td>
<td>Number of bits</td>
<td>Smallest value</td>
<td>Largest value</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">Int8</span></tt></td>
<td>✓</td>
<td>8</td>
<td>-2^7</td>
<td>2^7 - 1</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">Uint8</span></tt></td>
<td>&nbsp;</td>
<td>8</td>
<td>0</td>
<td>2^8 - 1</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">Int16</span></tt></td>
<td>✓</td>
<td>16</td>
<td>-2^15</td>
<td>2^15 - 1</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">Uint16</span></tt></td>
<td>&nbsp;</td>
<td>16</td>
<td>0</td>
<td>2^16 - 1</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">Int32</span></tt></td>
<td>✓</td>
<td>32</td>
<td>-2^31</td>
<td>2^31 - 1</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">Uint32</span></tt></td>
<td>&nbsp;</td>
<td>32</td>
<td>0</td>
<td>2^32 - 1</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">Int64</span></tt></td>
<td>✓</td>
<td>64</td>
<td>-2^63</td>
<td>2^63 - 1</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">Uint64</span></tt></td>
<td>&nbsp;</td>
<td>64</td>
<td>0</td>
<td>2^64 - 1</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">Int128</span></tt></td>
<td>✓</td>
<td>128</td>
<td>-2^127</td>
<td>2^127 - 1</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">Uint128</span></tt></td>
<td>&nbsp;</td>
<td>128</td>
<td>0</td>
<td>2^128 - 1</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">Bool</span></tt></td>
<td>N/A</td>
<td>8</td>
<td><tt class="docutils literal"><span class="pre">false</span></tt> (0)</td>
<td><tt class="docutils literal"><span class="pre">true</span></tt> (1)</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">Char</span></tt></td>
<td>N/A</td>
<td>32</td>
<td><tt class="docutils literal"><span class="pre">'\0'</span></tt></td>
<td><tt class="docutils literal"><span class="pre">'\Uffffffff'</span></tt></td>
</tr>
</tbody>
</table>
<p><tt class="docutils literal"><span class="pre">Char</span></tt> natively supports representation of
<a class="reference external" href="http://en.wikipedia.org/wiki/Unicode">Unicode characters</a>; see
<a class="reference internal" href="strings.html#man-strings"><em>Strings</em></a> for more details.</p>
<ul class="simple">
<li><strong>Floating-point types:</strong></li>
</ul>
<table border="1" class="docutils">
<colgroup>
<col width="32%" />
<col width="26%" />
<col width="41%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td>Type</td>
<td>Precision</td>
<td>Number of bits</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">Float16</span></tt></td>
<td><a class="reference external" href="http://en.wikipedia.org/wiki/Half-precision_floating-point_format">half</a></td>
<td>16</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">Float32</span></tt></td>
<td><a class="reference external" href="http://en.wikipedia.org/wiki/Single_precision_floating-point_format">single</a></td>
<td>32</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">Float64</span></tt></td>
<td><a class="reference external" href="http://en.wikipedia.org/wiki/Double_precision_floating-point_format">double</a></td>
<td>64</td>
</tr>
</tbody>
</table>
<p>Additionally, full support for <a class="reference internal" href="complex-and-rational-numbers.html#man-complex-and-rational-numbers"><em>Complex and Rational Numbers</em></a> is built
on top of these primitive numeric types. All numeric types interoperate
naturally without explicit casting, thanks to a flexible, user-extensible
<a class="reference internal" href="conversion-and-promotion.html#man-conversion-and-promotion"><em>type promotion system</em></a>.</p>
<div class="section" id="integers">
<h2>Integers<a class="headerlink" href="#integers" title="Permalink to this headline">¶</a></h2>
<p>Literal integers are represented in the standard manner:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="mi">1</span>
<span class="mi">1</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mi">1234</span>
<span class="mi">1234</span>
</pre></div>
</div>
<p>The default type for an integer literal depends on whether the target
system has a 32-bit architecture or a 64-bit architecture:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="c"># 32-bit system:</span>
<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">typeof</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="kt">Int32</span>

<span class="c"># 64-bit system:</span>
<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">typeof</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="kt">Int64</span>
</pre></div>
</div>
<p>The Julia internal variable <tt class="docutils literal"><span class="pre">WORD_SIZE</span></tt> indicates whether the target system
is 32-bit or 64-bit.:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="c"># 32-bit system:</span>
<span class="n">julia</span><span class="o">&gt;</span> <span class="n">WORD_SIZE</span>
<span class="mi">32</span>

<span class="c"># 64-bit system:</span>
<span class="n">julia</span><span class="o">&gt;</span> <span class="n">WORD_SIZE</span>
<span class="mi">64</span>
</pre></div>
</div>
<p>Julia also defines the types <tt class="docutils literal"><span class="pre">Int</span></tt> and <tt class="docutils literal"><span class="pre">Uint</span></tt>, which are aliases for the
system&#8217;s signed and unsigned native integer types respectively.:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="c"># 32-bit system:</span>
<span class="n">julia</span><span class="o">&gt;</span> <span class="kt">Int</span>
<span class="kt">Int32</span>
<span class="n">julia</span><span class="o">&gt;</span> <span class="kt">Uint</span>
<span class="kt">Uint32</span>


<span class="c"># 64-bit system:</span>
<span class="n">julia</span><span class="o">&gt;</span> <span class="kt">Int</span>
<span class="kt">Int64</span>
<span class="n">julia</span><span class="o">&gt;</span> <span class="kt">Uint</span>
<span class="kt">Uint64</span>
</pre></div>
</div>
<p>Larger integer literals that cannot be represented using only 32 bits
but can be represented in 64 bits always create 64-bit integers,
regardless of the system type:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="c"># 32-bit or 64-bit system:</span>
<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">typeof</span><span class="p">(</span><span class="mi">3000000000</span><span class="p">)</span>
<span class="kt">Int64</span>
</pre></div>
</div>
<p>Unsigned integers are input and output using the <tt class="docutils literal"><span class="pre">0x</span></tt> prefix and hexadecimal
(base 16) digits <tt class="docutils literal"><span class="pre">0-9a-f</span></tt> (the capitalized digits <tt class="docutils literal"><span class="pre">A-F</span></tt> also work for input).
The size of the unsigned value is determined by the number of hex digits used:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="mh">0x1</span>
<span class="mh">0x01</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">typeof</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span>
<span class="kt">Uint8</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mh">0x123</span>
<span class="mh">0x0123</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">typeof</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span>
<span class="kt">Uint16</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mh">0x1234567</span>
<span class="mh">0x01234567</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">typeof</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span>
<span class="kt">Uint32</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mh">0x123456789abcdef</span>
<span class="mh">0x0123456789abcdef</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">typeof</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span>
<span class="kt">Uint64</span>
</pre></div>
</div>
<p>This behavior is based on the observation that when one uses unsigned
hex literals for integer values, one typically is using them to
represent a fixed numeric byte sequence, rather than just an integer
value.</p>
<p>Recall that the variable <tt class="docutils literal"><span class="pre">ans</span></tt> is set to the value of the last expression
evaluated in an interactive session. This does not occur when Julia code is
run in other ways.</p>
<p>Binary and octal literals are also supported:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="m-Binary">0b10</span>
<span class="mh">0x02</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">typeof</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span>
<span class="kt">Uint8</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mo">0o10</span>
<span class="mh">0x08</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">typeof</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span>
<span class="kt">Uint8</span>
</pre></div>
</div>
<p>The minimum and maximum representable values of primitive numeric types
such as integers are given by the <tt class="docutils literal"><span class="pre">typemin</span></tt> and <tt class="docutils literal"><span class="pre">typemax</span></tt> functions:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="p">(</span><span class="nb">typemin</span><span class="p">(</span><span class="kt">Int32</span><span class="p">),</span> <span class="nb">typemax</span><span class="p">(</span><span class="kt">Int32</span><span class="p">))</span>
<span class="p">(</span><span class="o">-</span><span class="mi">2147483648</span><span class="p">,</span><span class="mi">2147483647</span><span class="p">)</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="k">for</span> <span class="n">T</span> <span class="o">=</span> <span class="p">{</span><span class="kt">Int8</span><span class="p">,</span><span class="kt">Int16</span><span class="p">,</span><span class="kt">Int32</span><span class="p">,</span><span class="kt">Int64</span><span class="p">,</span><span class="n">Int128</span><span class="p">,</span><span class="kt">Uint8</span><span class="p">,</span><span class="kt">Uint16</span><span class="p">,</span><span class="kt">Uint32</span><span class="p">,</span><span class="kt">Uint64</span><span class="p">,</span><span class="n">Uint128</span><span class="p">}</span>
         <span class="n">println</span><span class="p">(</span><span class="s">&quot;</span><span class="si">$</span><span class="s">(lpad(T,7)): [</span><span class="si">$</span><span class="s">(typemin(T)),</span><span class="si">$</span><span class="s">(typemax(T))]&quot;</span><span class="p">)</span>
       <span class="k">end</span>
   <span class="kt">Int8</span><span class="p">:</span> <span class="p">[</span><span class="o">-</span><span class="mi">128</span><span class="p">,</span><span class="mi">127</span><span class="p">]</span>
  <span class="kt">Int16</span><span class="p">:</span> <span class="p">[</span><span class="o">-</span><span class="mi">32768</span><span class="p">,</span><span class="mi">32767</span><span class="p">]</span>
  <span class="kt">Int32</span><span class="p">:</span> <span class="p">[</span><span class="o">-</span><span class="mi">2147483648</span><span class="p">,</span><span class="mi">2147483647</span><span class="p">]</span>
  <span class="kt">Int64</span><span class="p">:</span> <span class="p">[</span><span class="o">-</span><span class="mi">9223372036854775808</span><span class="p">,</span><span class="mi">9223372036854775807</span><span class="p">]</span>
 <span class="n">Int128</span><span class="p">:</span> <span class="p">[</span><span class="o">-</span><span class="mi">170141183460469231731687303715884105728</span><span class="p">,</span><span class="mi">170141183460469231731687303715884105727</span><span class="p">]</span>
  <span class="kt">Uint8</span><span class="p">:</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">255</span><span class="p">]</span>
 <span class="kt">Uint16</span><span class="p">:</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">65535</span><span class="p">]</span>
 <span class="kt">Uint32</span><span class="p">:</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">4294967295</span><span class="p">]</span>
 <span class="kt">Uint64</span><span class="p">:</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">18446744073709551615</span><span class="p">]</span>
<span class="n">Uint128</span><span class="p">:</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">340282366920938463463374607431768211455</span><span class="p">]</span>
</pre></div>
</div>
<p>The values returned by <tt class="docutils literal"><span class="pre">typemin</span></tt> and <tt class="docutils literal"><span class="pre">typemax</span></tt> are always of the
given argument type. (The above expression uses several features we have
yet to introduce, including <a class="reference internal" href="control-flow.html#man-loops"><em>for loops</em></a>,
<a class="reference internal" href="strings.html#man-strings"><em>Strings</em></a>, and <a class="reference internal" href="strings.html#man-string-interpolation"><em>Interpolation</em></a>,
but should be easy enough to understand for users with some existing
programming experience.)</p>
<div class="section" id="overflow-behavior">
<h3>Overflow behavior<a class="headerlink" href="#overflow-behavior" title="Permalink to this headline">¶</a></h3>
<p>In Julia, exceeding the maximum representable value of a given type results in
a wraparound behavior:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">x</span> <span class="o">=</span> <span class="nb">typemax</span><span class="p">(</span><span class="kt">Int64</span><span class="p">)</span>
<span class="mi">9223372036854775807</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">1</span>
<span class="o">-</span><span class="mi">9223372036854775808</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">==</span> <span class="nb">typemin</span><span class="p">(</span><span class="kt">Int64</span><span class="p">)</span>
<span class="n">true</span>
</pre></div>
</div>
<p>Thus, arithmetic with Julia integers is actually a form of <a class="reference external" href="http://en.wikipedia.org/wiki/Modular_arithmetic">modular arithmetic</a>. This reflects the
characteristics of the underlying arithmetic of integers as implemented on
modern computers. In applications where overflow is possible, explicit checking
for wraparound produced by overflow is essential; otherwise, the <tt class="docutils literal"><span class="pre">BigInt</span></tt> type
in <a class="reference internal" href="#man-arbitrary-precision-arithmetic"><em>Arbitrary Precision Arithmetic</em></a> is recommended instead.</p>
<p>To minimize the practical impact of this overflow, integer addition,
subtraction, multiplication, and exponentiation operands are promoted
to <tt class="docutils literal"><span class="pre">Int</span></tt> or <tt class="docutils literal"><span class="pre">Uint</span></tt> from narrower integer types.  (However,
divisions, remainders, and bitwise operations do not promote narrower
types.)</p>
</div>
<div class="section" id="division-errors">
<h3>Division errors<a class="headerlink" href="#division-errors" title="Permalink to this headline">¶</a></h3>
<p>Integer division (the <tt class="docutils literal"><span class="pre">div</span></tt> function) has two exceptional cases: dividing by
zero, and dividing the lowest negative number (<tt class="docutils literal"><span class="pre">typemin</span></tt>) by -1. Both of
these cases throw a <tt class="docutils literal"><span class="pre">DivideError</span></tt>. The remainder and modulus functions
(<tt class="docutils literal"><span class="pre">rem</span></tt> and <tt class="docutils literal"><span class="pre">mod</span></tt>) throw a <tt class="docutils literal"><span class="pre">DivideError</span></tt> when their second argument is
zero.</p>
</div>
</div>
<div class="section" id="floating-point-numbers">
<h2>Floating-Point Numbers<a class="headerlink" href="#floating-point-numbers" title="Permalink to this headline">¶</a></h2>
<p>Literal floating-point numbers are represented in the standard formats:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="mf">1.0</span>
<span class="mf">1.0</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mf">1.</span>
<span class="mf">1.0</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mf">0.5</span>
<span class="mf">0.5</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="o">.</span><span class="mi">5</span>
<span class="mf">0.5</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="o">-</span><span class="mf">1.23</span>
<span class="o">-</span><span class="mf">1.23</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mf">1e10</span>
<span class="mf">1.0e10</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mf">2.5e-4</span>
<span class="mf">0.00025</span>
</pre></div>
</div>
<p>The above results are all <tt class="docutils literal"><span class="pre">Float64</span></tt> values. Literal <tt class="docutils literal"><span class="pre">Float32</span></tt> values can
be entered by writing an <tt class="docutils literal"><span class="pre">f</span></tt> in place of <tt class="docutils literal"><span class="pre">e</span></tt>:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="mf">0.5f0</span>
<span class="mf">0.5f0</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">typeof</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span>
<span class="kt">Float32</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mf">2.5f-4</span>
<span class="mf">0.00025f0</span>
</pre></div>
</div>
<p>Values can be converted to <tt class="docutils literal"><span class="pre">Float32</span></tt> easily:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">float32</span><span class="p">(</span><span class="o">-</span><span class="mf">1.5</span><span class="p">)</span>
<span class="o">-</span><span class="mf">1.5f0</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">typeof</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span>
<span class="kt">Float32</span>
</pre></div>
</div>
<p>Hexadecimal floating-point literals are also valid, but only as <tt class="docutils literal"><span class="pre">Float64</span></tt> values:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="mh">0x1</span><span class="n">p0</span>
<span class="mf">1.0</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mh">0x1</span><span class="o">.</span><span class="mi">8</span><span class="n">p3</span>
<span class="mf">12.0</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mi">0</span><span class="n">x</span><span class="o">.</span><span class="mi">4</span><span class="n">p</span><span class="o">-</span><span class="mi">1</span>
<span class="mf">0.125</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">typeof</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span>
<span class="kt">Float64</span>
</pre></div>
</div>
<p>Half-precision floating-point numbers are also supported (<tt class="docutils literal"><span class="pre">Float16</span></tt>), but
only as a storage format. In calculations they&#8217;ll be converted to <tt class="docutils literal"><span class="pre">Float32</span></tt>:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="nb">sizeof</span><span class="p">(</span><span class="n">float16</span><span class="p">(</span><span class="mf">4.</span><span class="p">))</span>
<span class="mi">2</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mi">2</span><span class="o">*</span><span class="n">float16</span><span class="p">(</span><span class="mf">4.</span><span class="p">)</span>
<span class="mf">8.0f0</span>
</pre></div>
</div>
<div class="section" id="floating-point-zero">
<h3>Floating-point zero<a class="headerlink" href="#floating-point-zero" title="Permalink to this headline">¶</a></h3>
<p>Floating-point numbers have <a class="reference external" href="http://en.wikipedia.org/wiki/Signed_zero">two zeros</a>, positive zero and negative zero.
They are equal to each other but have different binary representations, as can
be seen using the <tt class="docutils literal"><span class="pre">bits</span></tt> function: :</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="mf">0.0</span> <span class="o">==</span> <span class="o">-</span><span class="mf">0.0</span>
<span class="n">true</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">bits</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
<span class="s">&quot;0000000000000000000000000000000000000000000000000000000000000000&quot;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">bits</span><span class="p">(</span><span class="o">-</span><span class="mf">0.0</span><span class="p">)</span>
<span class="s">&quot;1000000000000000000000000000000000000000000000000000000000000000&quot;</span>
</pre></div>
</div>
</div>
<div class="section" id="special-floating-point-values">
<span id="man-special-floats"></span><h3>Special floating-point values<a class="headerlink" href="#special-floating-point-values" title="Permalink to this headline">¶</a></h3>
<p>There are three specified standard floating-point values that do not
correspond to any point on the real number line:</p>
<table border="1" class="docutils">
<colgroup>
<col width="10%" />
<col width="10%" />
<col width="10%" />
<col width="15%" />
<col width="57%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head" colspan="3">Special value</th>
<th class="head">Name</th>
<th class="head">Description</th>
</tr>
<tr class="row-even"><th class="head"><tt class="docutils literal"><span class="pre">Float16</span></tt></th>
<th class="head"><tt class="docutils literal"><span class="pre">Float32</span></tt></th>
<th class="head"><tt class="docutils literal"><span class="pre">Float64</span></tt></th>
<th class="head">&nbsp;</th>
<th class="head">&nbsp;</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">Inf16</span></tt></td>
<td><tt class="docutils literal"><span class="pre">Inf32</span></tt></td>
<td><tt class="docutils literal"><span class="pre">Inf</span></tt></td>
<td>positive infinity</td>
<td>a value greater than all finite floating-point values</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">-Inf16</span></tt></td>
<td><tt class="docutils literal"><span class="pre">-Inf32</span></tt></td>
<td><tt class="docutils literal"><span class="pre">-Inf</span></tt></td>
<td>negative infinity</td>
<td>a value less than all finite floating-point values</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">NaN16</span></tt></td>
<td><tt class="docutils literal"><span class="pre">NaN32</span></tt></td>
<td><tt class="docutils literal"><span class="pre">NaN</span></tt></td>
<td>not a number</td>
<td>a value not <tt class="docutils literal"><span class="pre">==</span></tt> to any floating-point value (including itself)</td>
</tr>
</tbody>
</table>
<p>For further discussion of how these non-finite floating-point values are
ordered with respect to each other and other floats, see
<a class="reference internal" href="mathematical-operations.html#man-numeric-comparisons"><em>Numeric Comparisons</em></a>. By the
<a class="reference external" href="http://en.wikipedia.org/wiki/IEEE_754-2008">IEEE 754 standard</a>, these
floating-point values are the results of certain arithmetic operations:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="mi">1</span><span class="o">/</span><span class="nb">Inf</span>
<span class="mf">0.0</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mi">1</span><span class="o">/</span><span class="mi">0</span>
<span class="nb">Inf</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="o">-</span><span class="mi">5</span><span class="o">/</span><span class="mi">0</span>
<span class="o">-</span><span class="nb">Inf</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mf">0.000001</span><span class="o">/</span><span class="mi">0</span>
<span class="nb">Inf</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mi">0</span><span class="o">/</span><span class="mi">0</span>
<span class="n">NaN</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mi">500</span> <span class="o">+</span> <span class="nb">Inf</span>
<span class="nb">Inf</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mi">500</span> <span class="o">-</span> <span class="nb">Inf</span>
<span class="o">-</span><span class="nb">Inf</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">Inf</span> <span class="o">+</span> <span class="nb">Inf</span>
<span class="nb">Inf</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">Inf</span> <span class="o">-</span> <span class="nb">Inf</span>
<span class="n">NaN</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">Inf</span> <span class="o">*</span> <span class="nb">Inf</span>
<span class="nb">Inf</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">Inf</span> <span class="o">/</span> <span class="nb">Inf</span>
<span class="n">NaN</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mi">0</span> <span class="o">*</span> <span class="nb">Inf</span>
<span class="n">NaN</span>
</pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">typemin</span></tt> and <tt class="docutils literal"><span class="pre">typemax</span></tt> functions also apply to floating-point
types:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="p">(</span><span class="nb">typemin</span><span class="p">(</span><span class="n">Float16</span><span class="p">),</span><span class="nb">typemax</span><span class="p">(</span><span class="n">Float16</span><span class="p">))</span>
<span class="p">(</span><span class="o">-</span><span class="n">Inf16</span><span class="p">,</span><span class="n">Inf16</span><span class="p">)</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="p">(</span><span class="nb">typemin</span><span class="p">(</span><span class="kt">Float32</span><span class="p">),</span><span class="nb">typemax</span><span class="p">(</span><span class="kt">Float32</span><span class="p">))</span>
<span class="p">(</span><span class="o">-</span><span class="n">Inf32</span><span class="p">,</span><span class="n">Inf32</span><span class="p">)</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="p">(</span><span class="nb">typemin</span><span class="p">(</span><span class="kt">Float64</span><span class="p">),</span><span class="nb">typemax</span><span class="p">(</span><span class="kt">Float64</span><span class="p">))</span>
<span class="p">(</span><span class="o">-</span><span class="nb">Inf</span><span class="p">,</span><span class="nb">Inf</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="machine-epsilon">
<h3>Machine epsilon<a class="headerlink" href="#machine-epsilon" title="Permalink to this headline">¶</a></h3>
<p>Most real numbers cannot be represented exactly with floating-point numbers,
and so for many purposes it is important to know the distance between two
adjacent representable floating-point numbers, which is often known as
<a class="reference external" href="http://en.wikipedia.org/wiki/Machine_epsilon">machine epsilon</a>.</p>
<p>Julia provides the <tt class="docutils literal"><span class="pre">eps</span></tt> function, which gives the distance between <tt class="docutils literal"><span class="pre">1.0</span></tt>
and the next larger representable floating-point value:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="nb">eps</span><span class="p">(</span><span class="kt">Float32</span><span class="p">)</span>
<span class="mf">1.1920929f-7</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">eps</span><span class="p">(</span><span class="kt">Float64</span><span class="p">)</span>
<span class="mf">2.220446049250313e-16</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">eps</span><span class="p">()</span> <span class="c"># same as eps(Float64)</span>
<span class="mf">2.220446049250313e-16</span>
</pre></div>
</div>
<p>These values are <tt class="docutils literal"><span class="pre">2.0^-23</span></tt> and <tt class="docutils literal"><span class="pre">2.0^-52</span></tt> as <tt class="docutils literal"><span class="pre">Float32</span></tt> and <tt class="docutils literal"><span class="pre">Float64</span></tt>
values, respectively. The <tt class="docutils literal"><span class="pre">eps</span></tt> function can also take a
floating-point value as an argument, and gives the absolute difference
between that value and the next representable floating point value. That
is, <tt class="docutils literal"><span class="pre">eps(x)</span></tt> yields a value of the same type as <tt class="docutils literal"><span class="pre">x</span></tt> such that
<tt class="docutils literal"><span class="pre">x</span> <span class="pre">+</span> <span class="pre">eps(x)</span></tt> is the next representable floating-point value larger
than <tt class="docutils literal"><span class="pre">x</span></tt>:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="nb">eps</span><span class="p">(</span><span class="mf">1.0</span><span class="p">)</span>
<span class="mf">2.220446049250313e-16</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">eps</span><span class="p">(</span><span class="mf">1000.</span><span class="p">)</span>
<span class="mf">1.1368683772161603e-13</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">eps</span><span class="p">(</span><span class="mf">1e-27</span><span class="p">)</span>
<span class="mf">1.793662034335766e-43</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">eps</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
<span class="mf">5.0e-324</span>
</pre></div>
</div>
<p>The distance between two adjacent representable floating-point numbers is not
constant, but is smaller for smaller values and larger for larger values. In
other words, the representable floating-point numbers are densest in the real
number line near zero, and grow sparser exponentially as one moves farther away
from zero. By definition, <tt class="docutils literal"><span class="pre">eps(1.0)</span></tt> is the same as <tt class="docutils literal"><span class="pre">eps(Float64)</span></tt> since
<tt class="docutils literal"><span class="pre">1.0</span></tt> is a 64-bit floating-point value.</p>
<p>Julia also provides the <tt class="docutils literal"><span class="pre">nextfloat</span></tt> and <tt class="docutils literal"><span class="pre">prevfloat</span></tt> functions which return
the next largest or smallest representable floating-point number to the
argument respectively: :</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">x</span> <span class="o">=</span> <span class="mf">1.25f0</span>
<span class="mf">1.25f0</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">nextfloat</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="mf">1.2500001f0</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">prevfloat</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="mf">1.2499999f0</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">bits</span><span class="p">(</span><span class="n">prevfloat</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
<span class="s">&quot;00111111100111111111111111111111&quot;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">bits</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="s">&quot;00111111101000000000000000000000&quot;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">bits</span><span class="p">(</span><span class="n">nextfloat</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
<span class="s">&quot;00111111101000000000000000000001&quot;</span>
</pre></div>
</div>
<p>This example highlights the general principle that the adjacent representable
floating-point numbers also have adjacent binary integer representations.</p>
</div>
<div class="section" id="rounding-modes">
<h3>Rounding modes<a class="headerlink" href="#rounding-modes" title="Permalink to this headline">¶</a></h3>
<p>If a number doesn&#8217;t have an exact floating-point representation, it must be
rounded to an appropriate representable value, however, if wanted, the manner
in which this rounding is done can be changed according to the rounding modes
presented in the <a class="reference external" href="http://en.wikipedia.org/wiki/IEEE_754-2008">IEEE 754 standard</a>:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="mf">1.1</span> <span class="o">+</span> <span class="mf">0.1</span>
<span class="mf">1.2000000000000002</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">with_rounding</span><span class="p">(</span><span class="kt">Float64</span><span class="p">,</span><span class="n">RoundDown</span><span class="p">)</span> <span class="k">do</span>
       <span class="mf">1.1</span> <span class="o">+</span> <span class="mf">0.1</span>
       <span class="k">end</span>
<span class="mf">1.2</span>
</pre></div>
</div>
<p>The default mode used is always <tt class="docutils literal"><span class="pre">RoundNearest</span></tt>, which rounds to the nearest
representable value, with ties rounded towards the nearest value with an even
least significant bit.</p>
</div>
<div class="section" id="background-and-references">
<h3>Background and References<a class="headerlink" href="#background-and-references" title="Permalink to this headline">¶</a></h3>
<p>Floating-point arithmetic entails many subtleties which can be surprising to
users who are unfamiliar with the low-level implementation details. However,
these subtleties are described in detail in most books on scientific
computation, and also in the following references:</p>
<ul class="simple">
<li>The definitive guide to floating point arithmetic is the <a class="reference external" href="http://standards.ieee.org/findstds/standard/754-2008.html">IEEE 754-2008
Standard</a>;
however, it is not available for free online.</li>
<li>For a brief but lucid presentation of how floating-point numbers are
represented, see John D. Cook&#8217;s <a class="reference external" href="http://www.johndcook.com/blog/2009/04/06/anatomy-of-a-floating-point-number/">article</a>
on the subject as well as his <a class="reference external" href="http://www.johndcook.com/blog/2009/04/06/numbers-are-a-leaky-abstraction/">introduction</a>
to some of the issues arising from how this representation differs in
behavior from the idealized abstraction of real numbers.</li>
<li>Also recommended is Bruce Dawson&#8217;s <a class="reference external" href="http://randomascii.wordpress.com/2012/05/20/thats-not-normalthe-performance-of-odd-floats/">series of blog posts on floating-point
numbers</a>.</li>
<li>For an excellent, in-depth discussion of floating-point numbers and issues of
numerical accuracy encountered when computing with them, see David Goldberg&#8217;s
paper <a class="reference external" href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.102.244&amp;rep=rep1&amp;type=pdf">What Every Computer Scientist Should Know About Floating-Point
Arithmetic</a>.</li>
<li>For even more extensive documentation of the history of, rationale for,
and issues with floating-point numbers, as well as discussion of many other
topics in numerical computing, see the <a class="reference external" href="http://www.cs.berkeley.edu/~wkahan/">collected writings</a> of <a class="reference external" href="http://en.wikipedia.org/wiki/William_Kahan">William Kahan</a>, commonly known as the &#8220;Father
of Floating-Point&#8221;. Of particular interest may be <a class="reference external" href="http://www.cs.berkeley.edu/~wkahan/ieee754status/754story.html">An Interview with the Old
Man of Floating-Point</a>.</li>
</ul>
</div>
</div>
<div class="section" id="arbitrary-precision-arithmetic">
<span id="man-arbitrary-precision-arithmetic"></span><h2>Arbitrary Precision Arithmetic<a class="headerlink" href="#arbitrary-precision-arithmetic" title="Permalink to this headline">¶</a></h2>
<p>To allow computations with arbitrary-precision integers and floating point numbers,
Julia wraps the <a class="reference external" href="https://gmplib.org">GNU Multiple Precision Arithmetic Library (GMP)</a> and the <a class="reference external" href="http://www.mpfr.org">GNU MPFR Library</a>, respectively.
The <cite>BigInt</cite> and <cite>BigFloat</cite> types are available in Julia for arbitrary precision
integer and floating point numbers respectively.</p>
<p>Constructors exist to create these types from primitive numerical types, or from <tt class="docutils literal"><span class="pre">String</span></tt>.
Once created, they participate in arithmetic with all other numeric types thanks to Julia&#8217;s
<a class="reference internal" href="conversion-and-promotion.html#man-conversion-and-promotion"><em>type promotion and conversion mechanism</em></a>. :</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">BigInt</span><span class="p">(</span><span class="nb">typemax</span><span class="p">(</span><span class="kt">Int64</span><span class="p">))</span> <span class="o">+</span> <span class="mi">1</span>
<span class="mi">9223372036854775808</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">BigInt</span><span class="p">(</span><span class="s">&quot;123456789012345678901234567890&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span>
<span class="mi">123456789012345678901234567891</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">BigFloat</span><span class="p">(</span><span class="s">&quot;1.23456789012345678901&quot;</span><span class="p">)</span>
<span class="mf">1.234567890123456789010000000000000000000000000000000000000000000000000000000004e+00</span> <span class="n">with</span> <span class="mi">256</span> <span class="n">bits</span> <span class="n">of</span> <span class="n">precision</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">BigFloat</span><span class="p">(</span><span class="mf">2.0</span><span class="o">^</span><span class="mi">66</span><span class="p">)</span> <span class="o">/</span> <span class="mi">3</span>
<span class="mf">2.459565876494606882133333333333333333333333333333333333333333333333333333333344e+19</span> <span class="n">with</span> <span class="mi">256</span> <span class="n">bits</span> <span class="n">of</span> <span class="n">precision</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">factorial</span><span class="p">(</span><span class="n">BigInt</span><span class="p">(</span><span class="mi">40</span><span class="p">))</span>
<span class="mi">815915283247897734345611269596115894272000000000</span>
</pre></div>
</div>
<p>However, type promotion between the primitive types above and
<cite>BigInt</cite>/<cite>BigFloat</cite> is not automatic and must be explicitly stated. :</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">x</span> <span class="o">=</span> <span class="nb">typemin</span><span class="p">(</span><span class="kt">Int64</span><span class="p">)</span>
<span class="o">-</span><span class="mi">9223372036854775808</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">x</span> <span class="o">=</span> <span class="n">x</span> <span class="o">-</span> <span class="mi">1</span>
<span class="mi">9223372036854775807</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">typeof</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="kt">Int64</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">y</span> <span class="o">=</span> <span class="n">BigInt</span><span class="p">(</span><span class="nb">typemin</span><span class="p">(</span><span class="kt">Int64</span><span class="p">))</span>
<span class="o">-</span><span class="mi">9223372036854775808</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">y</span> <span class="o">=</span> <span class="n">y</span> <span class="o">-</span> <span class="mi">1</span>
<span class="o">-</span><span class="mi">9223372036854775809</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">typeof</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="n">BigInt</span> <span class="p">(</span><span class="n">constructor</span> <span class="n">with</span> <span class="mi">10</span> <span class="n">methods</span><span class="p">)</span>
</pre></div>
</div>
<p>The default precision (in number of bits of the significand) and rounding
mode of <cite>BigFloat</cite> operations can be changed, and all further calculations
will take these changes in account:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">with_rounding</span><span class="p">(</span><span class="n">BigFloat</span><span class="p">,</span><span class="n">RoundUp</span><span class="p">)</span> <span class="k">do</span>
       <span class="n">BigFloat</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="n">BigFloat</span><span class="p">(</span><span class="s">&quot;0.1&quot;</span><span class="p">)</span>
       <span class="k">end</span>
<span class="mf">1.100000000000000000000000000000000000000000000000000000000000000000000000000003e+00</span> <span class="n">with</span> <span class="mi">256</span> <span class="n">bits</span> <span class="n">of</span> <span class="n">precision</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">with_rounding</span><span class="p">(</span><span class="n">BigFloat</span><span class="p">,</span><span class="n">RoundDown</span><span class="p">)</span> <span class="k">do</span>
       <span class="n">BigFloat</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="n">BigFloat</span><span class="p">(</span><span class="s">&quot;0.1&quot;</span><span class="p">)</span>
       <span class="k">end</span>
<span class="mf">1.099999999999999999999999999999999999999999999999999999999999999999999999999986e+00</span> <span class="n">with</span> <span class="mi">256</span> <span class="n">bits</span> <span class="n">of</span> <span class="n">precision</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">with_bigfloat_precision</span><span class="p">(</span><span class="mi">40</span><span class="p">)</span> <span class="k">do</span>
       <span class="n">BigFloat</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="n">BigFloat</span><span class="p">(</span><span class="s">&quot;0.1&quot;</span><span class="p">)</span>
       <span class="k">end</span>
<span class="mf">1.1000000000004e+00</span> <span class="n">with</span> <span class="mi">40</span> <span class="n">bits</span> <span class="n">of</span> <span class="n">precision</span>
</pre></div>
</div>
</div>
<div class="section" id="numeric-literal-coefficients">
<span id="man-numeric-literal-coefficients"></span><h2>Numeric Literal Coefficients<a class="headerlink" href="#numeric-literal-coefficients" title="Permalink to this headline">¶</a></h2>
<p>To make common numeric formulas and expressions clearer, Julia allows
variables to be immediately preceded by a numeric literal, implying
multiplication. This makes writing polynomial expressions much cleaner:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">x</span> <span class="o">=</span> <span class="mi">3</span>
<span class="mi">3</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mi">2</span><span class="n">x</span><span class="o">^</span><span class="mi">2</span> <span class="o">-</span> <span class="mi">3</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span>
<span class="mi">10</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mf">1.5</span><span class="n">x</span><span class="o">^</span><span class="mi">2</span> <span class="o">-</span> <span class="o">.</span><span class="mi">5</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span>
<span class="mf">13.0</span>
</pre></div>
</div>
<p>It also makes writing exponential functions more elegant:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="mi">2</span><span class="o">^</span><span class="mi">2</span><span class="n">x</span>
<span class="mi">64</span>
</pre></div>
</div>
<p>The precedence of numeric literal coefficients is the same as that of unary
operators such as negation. So <tt class="docutils literal"><span class="pre">2^3x</span></tt> is parsed as <tt class="docutils literal"><span class="pre">2^(3x)</span></tt>, and
<tt class="docutils literal"><span class="pre">2x^3</span></tt> is parsed as <tt class="docutils literal"><span class="pre">2*(x^3)</span></tt>.</p>
<p>Numeric literals also work as coefficients to parenthesized
expressions:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="mi">2</span><span class="p">(</span><span class="n">x</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">^</span><span class="mi">2</span> <span class="o">-</span> <span class="mi">3</span><span class="p">(</span><span class="n">x</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span>
<span class="mi">3</span>
</pre></div>
</div>
<p>Additionally, parenthesized expressions can be used as coefficients to
variables, implying multiplication of the expression by the variable:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="p">(</span><span class="n">x</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="n">x</span>
<span class="mi">6</span>
</pre></div>
</div>
<p>Neither juxtaposition of two parenthesized expressions, nor placing a
variable before a parenthesized expression, however, can be used to
imply multiplication:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="p">(</span><span class="n">x</span><span class="o">-</span><span class="mi">1</span><span class="p">)(</span><span class="n">x</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
<span class="n">ERROR</span><span class="p">:</span> <span class="n">type</span><span class="p">:</span> <span class="n">apply</span><span class="p">:</span> <span class="n">expected</span> <span class="n">Function</span><span class="p">,</span> <span class="n">got</span> <span class="kt">Int64</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">x</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
<span class="n">ERROR</span><span class="p">:</span> <span class="n">type</span><span class="p">:</span> <span class="n">apply</span><span class="p">:</span> <span class="n">expected</span> <span class="n">Function</span><span class="p">,</span> <span class="n">got</span> <span class="kt">Int64</span>
</pre></div>
</div>
<p>Both of these expressions are interpreted as function application: any
expression that is not a numeric literal, when immediately followed by a
parenthetical, is interpreted as a function applied to the values in
parentheses (see <a class="reference internal" href="functions.html#man-functions"><em>Functions</em></a> for more about functions).
Thus, in both of these cases, an error occurs since the left-hand value
is not a function.</p>
<p>The above syntactic enhancements significantly reduce the visual noise
incurred when writing common mathematical formulae. Note that no
whitespace may come between a numeric literal coefficient and the
identifier or parenthesized expression which it multiplies.</p>
<div class="section" id="syntax-conflicts">
<h3>Syntax Conflicts<a class="headerlink" href="#syntax-conflicts" title="Permalink to this headline">¶</a></h3>
<p>Juxtaposed literal coefficient syntax may conflict with two numeric literal
syntaxes: hexadecimal integer literals and engineering notation for
floating-point literals. Here are some situations where syntactic
conflicts arise:</p>
<ul class="simple">
<li>The hexadecimal integer literal expression <tt class="docutils literal"><span class="pre">0xff</span></tt> could be
interpreted as the numeric literal <tt class="docutils literal"><span class="pre">0</span></tt> multiplied by the variable
<tt class="docutils literal"><span class="pre">xff</span></tt>.</li>
<li>The floating-point literal expression <tt class="docutils literal"><span class="pre">1e10</span></tt> could be interpreted
as the numeric literal <tt class="docutils literal"><span class="pre">1</span></tt> multiplied by the variable <tt class="docutils literal"><span class="pre">e10</span></tt>, and
similarly with the equivalent <tt class="docutils literal"><span class="pre">E</span></tt> form.</li>
</ul>
<p>In both cases, we resolve the ambiguity in favor of interpretation as a
numeric literals:</p>
<ul class="simple">
<li>Expressions starting with <tt class="docutils literal"><span class="pre">0x</span></tt> are always hexadecimal literals.</li>
<li>Expressions starting with a numeric literal followed by <tt class="docutils literal"><span class="pre">e</span></tt> or
<tt class="docutils literal"><span class="pre">E</span></tt> are always floating-point literals.</li>
</ul>
</div>
</div>
<div class="section" id="literal-zero-and-one">
<h2>Literal zero and one<a class="headerlink" href="#literal-zero-and-one" title="Permalink to this headline">¶</a></h2>
<p>Julia provides functions which return literal 0 and 1 corresponding to a
specified type or the type of a given variable.</p>
<table border="1" class="docutils">
<colgroup>
<col width="17%" />
<col width="83%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td>Function</td>
<td>Description</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">zero(x)</span></tt></td>
<td>Literal zero of type <tt class="docutils literal"><span class="pre">x</span></tt> or type of variable <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">one(x)</span></tt></td>
<td>Literal one of type <tt class="docutils literal"><span class="pre">x</span></tt> or type of variable <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
</tbody>
</table>
<p>These functions are useful in <a class="reference internal" href="mathematical-operations.html#man-numeric-comparisons"><em>Numeric Comparisons</em></a> to avoid overhead
from unnecessary <a class="reference internal" href="conversion-and-promotion.html#man-conversion-and-promotion"><em>type conversion</em></a>.</p>
<p>Examples:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">zero</span><span class="p">(</span><span class="kt">Float32</span><span class="p">)</span>
<span class="mf">0.0f0</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">zero</span><span class="p">(</span><span class="mf">1.0</span><span class="p">)</span>
<span class="mf">0.0</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">one</span><span class="p">(</span><span class="kt">Int32</span><span class="p">)</span>
<span class="mi">1</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">one</span><span class="p">(</span><span class="n">BigFloat</span><span class="p">)</span>
<span class="mf">1e+00</span> <span class="n">with</span> <span class="mi">256</span> <span class="n">bits</span> <span class="n">of</span> <span class="n">precision</span>
</pre></div>
</div>
</div>
</div>


          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="mathematical-operations.html" class="btn btn-neutral float-right" title="Mathematical Operations and Elementary Functions"/>Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="variables.html" class="btn btn-neutral" title="Variables"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
    </p>
  </div>

  <a href="https://github.com/snide/sphinx_rtd_theme">Sphinx theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>
</footer>
        </div>
      </div>

    </section>

  </div>
  

  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../',
            VERSION:'0.3.4',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true
        };
    </script>
      <script type="text/javascript" src="../_static/jquery.js"></script>
      <script type="text/javascript" src="../_static/underscore.js"></script>
      <script type="text/javascript" src="../_static/doctools.js"></script>
      <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

  

  
  
    <script type="text/javascript" src="../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>