172 lines
No EOL
80 KiB
HTML
172 lines
No EOL
80 KiB
HTML
<!doctype html>
|
||
<html lang="en" dir="ltr" class="docs-wrapper plugin-docs plugin-id-default docs-version-current docs-doc-page docs-doc-id-chap-12/bc-b-number-concepts" data-has-hydrated="false">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="generator" content="Docusaurus v3.0.1">
|
||
<title data-rh="true">12.1 Number Concepts | Common Lisp (New) Language Reference</title><meta data-rh="true" name="viewport" content="width=device-width,initial-scale=1"><meta data-rh="true" name="twitter:card" content="summary_large_image"><meta data-rh="true" property="og:image" content="https://lisp-docs.github.io/cl-language-reference/img/1024px-Lisp_logo.svg.png"><meta data-rh="true" name="twitter:image" content="https://lisp-docs.github.io/cl-language-reference/img/1024px-Lisp_logo.svg.png"><meta data-rh="true" property="og:url" content="https://lisp-docs.github.io/cl-language-reference/chap-12/bc-b-number-concepts"><meta data-rh="true" property="og:locale" content="en"><meta data-rh="true" name="docusaurus_locale" content="en"><meta data-rh="true" name="docsearch:language" content="en"><meta data-rh="true" name="google-site-verification" content="Vzaw013_bfdKeUVG89Ch3W1zC9_vH9ID2dPB9Dz0vr0"><meta data-rh="true" name="docusaurus_version" content="current"><meta data-rh="true" name="docusaurus_tag" content="docs-default-current"><meta data-rh="true" name="docsearch:version" content="current"><meta data-rh="true" name="docsearch:docusaurus_tag" content="docs-default-current"><meta data-rh="true" property="og:title" content="12.1 Number Concepts | Common Lisp (New) Language Reference"><meta data-rh="true" name="description" content="12.1.1 Numeric Operations"><meta data-rh="true" property="og:description" content="12.1.1 Numeric Operations"><link data-rh="true" rel="icon" href="../img/favicon.ico"><link data-rh="true" rel="canonical" href="bc-b-number-concepts.html"><link data-rh="true" rel="alternate" href="bc-b-number-concepts.html" hreflang="en"><link data-rh="true" rel="alternate" href="bc-b-number-concepts.html" hreflang="x-default"><link data-rh="true" rel="preconnect" href="https://C1F2Q5VM6X-dsn.algolia.net" crossorigin="anonymous"><link rel="preconnect" href="https://www.google-analytics.com">
|
||
<link rel="preconnect" href="https://www.googletagmanager.com">
|
||
<script async src="https://www.googletagmanager.com/gtag/js?id=G-8TJCE4NSF8"></script>
|
||
<script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),gtag("config","G-8TJCE4NSF8",{})</script>
|
||
|
||
|
||
<link rel="search" type="application/opensearchdescription+xml" title="Common Lisp (New) Language Reference" href="../opensearch.xml"><link rel="stylesheet" href="../assets/css/styles.f13b59fe.css">
|
||
<script src="../assets/js/runtime~main.02699c25.js" defer="defer"></script>
|
||
<script src="../assets/js/main.4f0a7a76.js" defer="defer"></script>
|
||
</head>
|
||
<body class="navigation-with-keyboard">
|
||
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){try{return new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}}()||function(){try{return localStorage.getItem("theme")}catch(t){}}();t(null!==e?e:"light")}(),function(){try{const c=new URLSearchParams(window.location.search).entries();for(var[t,e]of c)if(t.startsWith("docusaurus-data-")){var a=t.replace("docusaurus-data-","data-");document.documentElement.setAttribute(a,e)}}catch(t){}}()</script><div id="__docusaurus"><div role="region" aria-label="Skip to main content"><a class="skipToContent_fXgn" href="bc-b-number-concepts.html#__docusaurus_skipToContent_fallback">Skip to main content</a></div><nav aria-label="Main" class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Toggle navigation bar" aria-expanded="false" class="navbar__toggle clean-btn" type="button"><svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a href="../../index.html" target="_blank" rel="noopener noreferrer" class="navbar__brand"><div class="navbar__logo"><img src="../img/logo.svg" alt="Lisp Logo" class="themedComponent_mlkZ themedComponent--light_NVdE"><img src="../img/logo.svg" alt="Lisp Logo" class="themedComponent_mlkZ themedComponent--dark_xIcU"></div><b class="navbar__title text--truncate">Common Lisp Docs</b></a><a href="../../docs/tutorial/index.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Tutorial</a><a href="../index.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Technical Reference</a><a href="../../docs/whylisp.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Why Lisp?</a><a href="../../docs/howto.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Guides</a></div><div class="navbar__items navbar__items--right"><a href="../../docs/contribute.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Contribute!</a><a href="../../docs/help.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Getting Help</a><a href="../../docs/about.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">About</a><a href="../../blog.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Blog</a><a href="https://github.com/lisp-docs" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">GitHub<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a><div class="toggle_vylO colorModeToggle_DEke"><button class="clean-btn toggleButton_gllP toggleButtonDisabled_aARS" type="button" disabled="" title="Switch between dark and light mode (currently light mode)" aria-label="Switch between dark and light mode (currently light mode)" aria-live="polite"><svg viewBox="0 0 24 24" width="24" height="24" class="lightToggleIcon_pyhR"><path fill="currentColor" d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z"></path></svg><svg viewBox="0 0 24 24" width="24" height="24" class="darkToggleIcon_wfgR"><path fill="currentColor" d="M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"></path></svg></button></div><div class="navbarSearchContainer_Bca1"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><svg width="20" height="20" class="DocSearch-Search-Icon" viewBox="0 0 20 20"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"></span></button></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div></nav><div id="__docusaurus_skipToContent_fallback" class="main-wrapper mainWrapper_z2l0"><div class="docsWrapper_hBAB"><button aria-label="Scroll back to top" class="clean-btn theme-back-to-top-button backToTopButton_sjWU" type="button"></button><div class="docRoot_UBD9"><aside class="theme-doc-sidebar-container docSidebarContainer_YfHR"><div class="sidebarViewport_aRkj"><div class="sidebar_njMd"><nav aria-label="Docs sidebar" class="menu thin-scrollbar menu_SIkG"><ul class="theme-doc-sidebar-menu menu__list"><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="../index.html">Introduction</a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-0/intro.html">Contents and Figures</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-1/b-b-scope-purpose-and-history.html">1. Introduction</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-2/c-b-character-syntax.html">2. Syntax</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-3/d-b-evaluation.html">3. Evaluation and Compilation</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-4/e-b-introduction.html">4. Types and Classes</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-5/f-b-generalized-reference.html">5. Data and Control Flow</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-6/g-b-the-loop-facility.html">6. Iteration</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-7/h-b-object-creation-and-initialization.html">7. Objects</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../category/81-structures-dictionary.html">8. Structures</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-9/j-b-condition-system-concepts.html">9. Conditions</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-10/ba-b-symbol-concepts.html">10. Symbols</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-11/bb-b-package-concepts.html">11. Packages</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret menu__link--active" aria-expanded="true" href="bc-b-number-concepts.html">12. Numbers</a></div><ul style="display:block;overflow:visible;height:auto" class="menu__list"><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link menu__link--active" aria-current="page" tabindex="0" href="bc-b-number-concepts.html">12.1 Number Concepts</a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" tabindex="0" href="../category/122-numbers-dictionary.html">12.2 Numbers Dictionary</a><button aria-label="Expand sidebar category '12.2 Numbers Dictionary'" type="button" class="clean-btn menu__caret"></button></div></li></ul></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-13/bd-b-character-concepts.html">13. Characters</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-14/be-b-cons-concepts.html">14. Conses</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-15/bf-b-array-concepts.html">15. Arrays</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-16/bg-b-string-concepts.html">16. Strings</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-17/bh-b-sequence-concepts.html">17. Sequences</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-18/bi-b-hash-table-concepts.html">18. Hash Tables</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-19/bj-b-overview-of-filenames.html">19. Filenames</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-20/ca-b-file-system-concepts.html">20. Files</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-21/cb-b-stream-concepts.html">21. Streams</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-22/cc-b-the-lisp-printer.html">22. Printer</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-23/cd-b-reader-concepts.html">23. Reader</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-24/ce-b-system-construction-concepts.html">24. System Construction</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-25/cf-b-the-external-environment.html">25. External Environment</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../environments.html">26. Environments</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../meta-object-protocol.html">27. Meta Object Protocol</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../data-structures.html">28. Data Structures</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../portability/trivial-packages.html">29. Portability</a></div></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="../dictionary-entries.html">dictionary-entries</a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="../chap-26/intro.html">Glossary</a></div></li></ul></nav></div></div></aside><main class="docMainContainer_TBSr"><div class="container padding-top--md padding-bottom--lg"><div class="row"><div class="col docItemCol_VOVn"><div class="docItemContainer_Djhp"><article><nav class="theme-doc-breadcrumbs breadcrumbsContainer_Z_bl" aria-label="Breadcrumbs"><ul class="breadcrumbs" itemscope="" itemtype="https://schema.org/BreadcrumbList"><li class="breadcrumbs__item"><a aria-label="Home page" class="breadcrumbs__link" href="../index.html"><svg viewBox="0 0 24 24" class="breadcrumbHomeIcon_YNFT"><path d="M10 19v-5h4v5c0 .55.45 1 1 1h3c.55 0 1-.45 1-1v-7h1.7c.46 0 .68-.57.33-.87L12.67 3.6c-.38-.34-.96-.34-1.34 0l-8.36 7.53c-.34.3-.13.87.33.87H5v7c0 .55.45 1 1 1h3c.55 0 1-.45 1-1z" fill="currentColor"></path></svg></a></li><li class="breadcrumbs__item"><span class="breadcrumbs__link">12. Numbers</span><meta itemprop="position" content="1"></li><li itemscope="" itemprop="itemListElement" itemtype="https://schema.org/ListItem" class="breadcrumbs__item breadcrumbs__item--active"><span class="breadcrumbs__link" itemprop="name">12.1 Number Concepts</span><meta itemprop="position" content="2"></li></ul></nav><div class="tocCollapsible_ETCw theme-doc-toc-mobile tocMobile_ITEo"><button type="button" class="clean-btn tocCollapsibleButton_TO0P">On this page</button></div><div class="theme-doc-markdown markdown"><h1>12.1 Number Concepts</h1>
|
||
<!-- -->
|
||
<!-- -->
|
||
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="1211-numeric-operations">12.1.1 Numeric Operations<a href="bc-b-number-concepts.html#1211-numeric-operations" class="hash-link" aria-label="Direct link to 12.1.1 Numeric Operations" title="Direct link to 12.1.1 Numeric Operations"></a></h2>
|
||
<!-- -->
|
||
<p>Common Lisp provides a large variety of operations related to <span><i>numbers</i></span>. This section provides an overview of those operations by grouping them into categories that emphasize some of the relationships among them.</p>
|
||
<p>Figure 12–1 shows <span><i>operators</i></span> relating to arithmetic operations.</p>
|
||
<p>|</p><p><strong>* 1+ gcd</strong> </p><p><strong>+ 1- incf</strong> </p><p><strong>- conjugate lcm</strong> </p><p><strong>/ decf</strong></p>|<p></p>
|
||
<p>| :- |</p>
|
||
<p><strong>Figure 12–1. Operators relating to Arithmetic.</strong></p>
|
||
<p>Figure 12–2 shows <span><i>defined names</i></span> relating to exponential, logarithmic, and trigonometric operations.</p>
|
||
<p>|</p><p><strong>abs cos signum</strong> </p><p><strong>acos cosh sin</strong> </p><p><strong>acosh exp sinh</strong> </p><p><strong>asin expt sqrt</strong> </p><p><strong>asinh isqrt tan</strong> </p><p><strong>atan log tanh</strong> </p><p><strong>atanh phase</strong> </p><p><strong>cis pi</strong></p>|<p></p>
|
||
<p>| :- |</p>
|
||
<p><strong>Figure 12–2. Defined names relating to Exponentials, Logarithms, and Trigonometry.</strong> Figure 12–3 shows <span><i>operators</i></span> relating to numeric comparison and predication.</p>
|
||
<p>|</p><p><span><b>/=</b></span> ><strong>= oddp</strong> </p><p>< <strong>evenp plusp</strong> </p><p><<strong>= max zerop</strong> </p><p><strong>= min</strong> </p><p>> <span><b>minusp</b></span></p>|<p></p>
|
||
<p>| :- |</p>
|
||
<p><strong>Figure 12–3. Operators for numeric comparison and predication.</strong></p>
|
||
<p>Figure 12–4 shows <span><i>defined names</i></span> relating to numeric type manipulation and coercion.</p>
|
||
<p>|</p><p><strong>ceiling float-radix rational</strong> </p><p><strong>complex float-sign rationalize decode-float floor realpart</strong> </p><p><strong>denominator fround rem</strong> </p><p><strong>fceiling ftruncate round</strong> </p><p><strong>ffloor imagpart scale-float float integer-decode-float truncate</strong> </p><p><strong>float-digits mod</strong> </p><p><strong>float-precision numerator</strong></p>|<p></p>
|
||
<p>| :- |</p>
|
||
<p><strong>Figure 12–4. Defined names relating to numeric type manipulation and coercion.</strong></p>
|
||
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="12111-associativity-and-commutativity-in-numeric-operations">12.1.1.1 Associativity and Commutativity in Numeric Operations<a href="bc-b-number-concepts.html#12111-associativity-and-commutativity-in-numeric-operations" class="hash-link" aria-label="Direct link to 12.1.1.1 Associativity and Commutativity in Numeric Operations" title="Direct link to 12.1.1.1 Associativity and Commutativity in Numeric Operations"></a></h3>
|
||
<!-- -->
|
||
<p>For functions that are mathematically associative (and possibly commutative), a <span><i>conforming implementation</i></span> may process the <span><i>arguments</i></span> in any manner consistent with associative (and possibly commutative) rearrangement. This does not affect the order in which the <span><i>argument</i></span></p>
|
||
<p><span><i>forms</i></span> are <em>evaluated</em>; for a discussion of evaluation order, see Section 3.1.2.1.2.3 (Function Forms). What is unspecified is only the order in which the <em>parameter values</em> are processed. This implies that <span><i>implementations</i></span> may differ in which automatic <em>coercions</em> are applied; see Section 12.1.1.2 (Contagion in Numeric Operations).</p>
|
||
<p>A <span><i>conforming program</i></span> can control the order of processing explicitly by separating the operations into separate (possibly nested) <span><i>function forms</i></span>, or by writing explicit calls to <span><i>functions</i></span> that perform coercions.</p>
|
||
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="121111-examples-of-associativity-and-commutativity-in-numeric-operations">12.1.1.1.1 Examples of Associativity and Commutativity in Numeric Operations<a href="bc-b-number-concepts.html#121111-examples-of-associativity-and-commutativity-in-numeric-operations" class="hash-link" aria-label="Direct link to 12.1.1.1.1 Examples of Associativity and Commutativity in Numeric Operations" title="Direct link to 12.1.1.1.1 Examples of Associativity and Commutativity in Numeric Operations"></a></h4>
|
||
<!-- -->
|
||
<div class="language-lisp codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-lisp codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">Consider the following expression, in which we assume that </span><span class="token number" style="color:#36acaa">1.0</span><span class="token plain"> and 1.0e-15 both denote *single floats*: </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">+</span><span class="token plain"> 1/3 2/3 1.0d0 </span><span class="token number" style="color:#36acaa">1.0</span><span class="token plain"> 1.0e-15</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">One *conforming implementation* might process the *arguments* from left to right, first adding 1/3 and 2/3 to get 1, then converting that to a *double float* for combination with 1.0d0, then successively converting and adding </span><span class="token number" style="color:#36acaa">1.0</span><span class="token plain"> and 1.0e-15. </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">Another *conforming implementation* might process the *arguments* from right to left, first performing a *single float* addition of </span><span class="token number" style="color:#36acaa">1.0</span><span class="token plain"> and 1.0e-15 </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">perhaps</span><span class="token plain"> losing accuracy in the process</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain">, then converting the sum to a *double float* and adding 1.0d0, then converting 2/3 to a *double float* and adding it, and then converting 1/3 and adding that. </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">A third *conforming implementation* might first scan all the *arguments*, process all the *rationals* first to keep that part of the computation exact, then find an *argument* of the largest floating-point </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">format among all the *arguments* and add that, and then add in all other *arguments*, converting each in turn </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">all</span><span class="token plain"> in a perhaps misguided attempt to make the computation as accurate as possible</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain">. </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">In any case, all three strategies are legitimate. </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">A *conforming program* could control the order by writing, for example, </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">+</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">+</span><span class="token plain"> 1/3 2/3</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">+</span><span class="token plain"> 1.0d0 1.0e-15</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1.0</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
|
||
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="12112-contagion-in-numeric-operations">12.1.1.2 Contagion in Numeric Operations<a href="bc-b-number-concepts.html#12112-contagion-in-numeric-operations" class="hash-link" aria-label="Direct link to 12.1.1.2 Contagion in Numeric Operations" title="Direct link to 12.1.1.2 Contagion in Numeric Operations"></a></h3>
|
||
<!-- -->
|
||
<p>For information about the contagion rules for implicit coercions of <span><i>arguments</i></span> in numeric operations, see Section 12.1.4.4 (Rule of Float Precision Contagion), Section 12.1.4.1 (Rule of Float and Rational Contagion), and Section 12.1.5.2 (Rule of Complex Contagion).</p>
|
||
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="12113-viewing-integers-as-bits-and-bytes">12.1.1.3 Viewing Integers as Bits and Bytes<a href="bc-b-number-concepts.html#12113-viewing-integers-as-bits-and-bytes" class="hash-link" aria-label="Direct link to 12.1.1.3 Viewing Integers as Bits and Bytes" title="Direct link to 12.1.1.3 Viewing Integers as Bits and Bytes"></a></h3>
|
||
<!-- -->
|
||
<!-- -->
|
||
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="121131-logical-operations-on-integers">12.1.1.3.1 Logical Operations on Integers<a href="bc-b-number-concepts.html#121131-logical-operations-on-integers" class="hash-link" aria-label="Direct link to 12.1.1.3.1 Logical Operations on Integers" title="Direct link to 12.1.1.3.1 Logical Operations on Integers"></a></h4>
|
||
<!-- -->
|
||
<p>Logical operations require <em>integers</em> as arguments; an error of <span><i>type</i></span> <span><b>type-error</b></span> should be signaled if an argument is supplied that is not an <em>integer</em> . <em>Integer</em> arguments to logical operations are treated as if they were represented in two’s-complement notation.</p>
|
||
<p>Figure 12–5 shows <span><i>defined names</i></span> relating to logical operations on numbers.</p>
|
||
<p>|</p><p><strong>ash boole-ior logbitp</strong> </p><p><strong>boole boole-nand logcount</strong> </p><p><strong>boole-1 boole-nor logeqv</strong> </p><p><strong>boole-2 boole-orc1 logior</strong> </p><p><strong>boole-and boole-orc2 lognand</strong> </p><p><strong>boole-andc1 boole-set lognor</strong> </p><p><strong>boole-andc2 boole-xor lognot</strong> </p><p><strong>boole-c1 integer-length logorc1</strong> </p><p><strong>boole-c2 logand logorc2</strong> </p><p><strong>boole-clr logandc1 logtest</strong> </p><p><strong>boole-eqv logandc2 logxor</strong></p>|<p></p>
|
||
<p>| :- |</p>
|
||
<p><strong>Figure 12–5. Defined names relating to logical operations on numbers.</strong></p>
|
||
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="121132-byte-operations-on-integers">12.1.1.3.2 Byte Operations on Integers<a href="bc-b-number-concepts.html#121132-byte-operations-on-integers" class="hash-link" aria-label="Direct link to 12.1.1.3.2 Byte Operations on Integers" title="Direct link to 12.1.1.3.2 Byte Operations on Integers"></a></h4>
|
||
<!-- -->
|
||
<p>The byte-manipulation <span><i>functions</i></span> use <span><i>objects</i></span> called <span><i>byte specifiers</i></span> to designate the size and position of a specific <span><i>byte</i></span> within an <em>integer</em> . The representation of a <span><i>byte specifier</i></span> is <em>implementation dependent</em>; it might or might not be a <span><i>number</i></span> . The <span><i>function</i></span> <span><b>byte</b></span> will construct a <span><i>byte specifier</i></span> , which various other byte-manipulation <span><i>functions</i></span> will accept.</p>
|
||
<p>Figure 12–6 shows <span><i>defined names</i></span> relating to manipulating <span><i>bytes</i></span> of <span><i>numbers</i></span>.</p>
|
||
<p>|</p><p><strong>byte deposit-field ldb-test</strong> </p><p><strong>byte-position dpb mask-field</strong> </p><p><strong>byte-size ldb</strong></p>|<p></p>
|
||
<p>| :- |</p>
|
||
<p><strong>Figure 12–6. Defined names relating to byte manipulation.</strong></p>
|
||
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="1212-implementation">12.1.2 Implementation<a href="bc-b-number-concepts.html#1212-implementation" class="hash-link" aria-label="Direct link to 12.1.2 Implementation" title="Direct link to 12.1.2 Implementation"></a></h2>
|
||
<!-- -->
|
||
<p>Figure 12–7 shows <span><i>defined names</i></span> relating to <span><i>implementation-dependent</i></span> details about <span><i>numbers</i></span>.</p>
|
||
<p>|</p><p><strong>double-float-epsilon most-negative-fixnum</strong> </p><p><strong>double-float-negative-epsilon most-negative-long-float</strong> </p><p><strong>least-negative-double-float most-negative-short-float</strong> </p><p><strong>least-negative-long-float most-negative-single-float</strong> </p><p><strong>least-negative-short-float most-positive-double-float</strong> </p><p><strong>least-negative-single-float most-positive-fixnum</strong> </p><p><strong>least-positive-double-float most-positive-long-float</strong> </p><p><strong>least-positive-long-float most-positive-short-float</strong> </p><p><strong>least-positive-short-float most-positive-single-float</strong> </p><p><strong>least-positive-single-float short-float-epsilon</strong> </p><p><strong>long-float-epsilon short-float-negative-epsilon long-float-negative-epsilon single-float-epsilon</strong> </p><p><strong>most-negative-double-float single-float-negative-epsilon</strong></p>|<p></p>
|
||
<p>| :- |</p>
|
||
<p><strong>Figure 12–7. Defined names relating to implementation-dependent details about numbers.</strong></p>
|
||
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="1213-rational-computations">12.1.3 Rational Computations<a href="bc-b-number-concepts.html#1213-rational-computations" class="hash-link" aria-label="Direct link to 12.1.3 Rational Computations" title="Direct link to 12.1.3 Rational Computations"></a></h2>
|
||
<!-- -->
|
||
<p>The rules in this section apply to <span><i>rational</i></span> computations.</p>
|
||
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="12131-rule-of-unbounded-rational-precision">12.1.3.1 Rule of Unbounded Rational Precision<a href="bc-b-number-concepts.html#12131-rule-of-unbounded-rational-precision" class="hash-link" aria-label="Direct link to 12.1.3.1 Rule of Unbounded Rational Precision" title="Direct link to 12.1.3.1 Rule of Unbounded Rational Precision"></a></h3>
|
||
<!-- -->
|
||
<p>Rational computations cannot overflow in the usual sense (though there may not be enough storage to represent a result), since <em>integers</em> and <span><i>ratios</i></span> may in principle be of any magnitude.</p>
|
||
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="12132-rule-of-canonical-representation-for-rationals">12.1.3.2 Rule of Canonical Representation for Rationals<a href="bc-b-number-concepts.html#12132-rule-of-canonical-representation-for-rationals" class="hash-link" aria-label="Direct link to 12.1.3.2 Rule of Canonical Representation for Rationals" title="Direct link to 12.1.3.2 Rule of Canonical Representation for Rationals"></a></h3>
|
||
<!-- -->
|
||
<p>If any computation produces a result that is a mathematical ratio of two integers such that the denominator evenly divides the numerator, then the result is converted to the equivalent <em>integer</em> .</p>
|
||
<p>If the denominator does not evenly divide the numerator, the canonical representation of a <span><i>rational</i></span> number is as the <span><i>ratio</i></span> that numerator and that denominator, where the greatest common divisor of the numerator and denominator is one, and where the denominator is positive and greater than one.</p>
|
||
<p>When used as input (in the default syntax), the notation -0 always denotes the <em>integer</em> 0. A <span><i>conforming implementation</i></span> must not have a representation of “minus zero” for <em>integers</em> that is distinct from its representation of zero for <em>integers</em>. However, such a distinction is possible for <span><i>floats</i></span>; see the <span><i>type</i></span> <span><b>float</b></span>.</p>
|
||
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="12133-rule-of-float-substitutability">12.1.3.3 Rule of Float Substitutability<a href="bc-b-number-concepts.html#12133-rule-of-float-substitutability" class="hash-link" aria-label="Direct link to 12.1.3.3 Rule of Float Substitutability" title="Direct link to 12.1.3.3 Rule of Float Substitutability"></a></h3>
|
||
<!-- -->
|
||
<p>When the arguments to an irrational mathematical <span><i>function</i></span> are all <span><i>rational</i></span> and the true mathe matical result is also (mathematically) rational, then unless otherwise noted an implementation is free to return either an accurate <span><i>rational</i></span> result or a <span><i>single float</i></span> approximation. If the arguments</p>
|
||
<p>are all <span><i>rational</i></span> but the result cannot be expressed as a <span><i>rational</i></span> number, then a <span><i>single float</i></span> approximation is always returned.</p>
|
||
<p>If the arguments to an irrational mathematical <span><i>function</i></span> are all of type</p>
|
||
<p>(or rational (complex rational)) and the true mathematical result is (mathematically) a complex number with rational real and imaginary parts, then unless otherwise noted an imple mentation is free to return either an accurate result of type (or rational (complex rational)) or a <span><i>single float</i></span> (permissible only if the imaginary part of the true mathematical result is zero) or (complex single-float). If the arguments are all of type (or rational (complex rational)) but the result cannot be expressed as a <span><i>rational</i></span> or <span><i>complex rational</i></span>, then the returned value will be of <span><i>type</i></span> <span><b>single-float</b></span> (permissible only if the imaginary part of the true mathematical result is zero) or (complex single-float).</p>
|
||
<p>Float substitutability applies neither to the rational <span><i>functions</i></span> <span><b>+</b></span>, <span><b>-</b></span>, <strong>*</strong>, and <span><b>/</b></span> nor to the related <span><i>operators</i></span> <span><b>1+</b></span>, <strong>1-</strong>, <span><b>incf</b></span>, <span><b>decf</b></span>, and <span><b>conjugate</b></span>. For rational <span><i>functions</i></span>, if all arguments are <span><i>rational</i></span>, then the result is <span><i>rational</i></span>; if all arguments are of type (or rational (complex rational)), then the result is of type (or rational (complex rational)).</p>
|
||
<p>|<strong>Function Sample Results</strong>|</p>
|
||
<p>| :- |</p>
|
||
<p>|</p><p><span><b>abs</b></span> (abs #c(3 4)) → 5 <em>or</em> 5.0 </p><p><span><b>acos</b></span> (acos 1) |