{"id":18510044,"url":"https://github.com/lfex/complex","last_synced_at":"2025-10-05T19:32:08.996Z","repository":{"id":36092626,"uuid":"40393579","full_name":"lfex/complex","owner":"lfex","description":"LFE support for numbers both real and imagined","archived":false,"fork":false,"pushed_at":"2021-06-08T14:26:17.000Z","size":2245,"stargazers_count":7,"open_issues_count":5,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-01-26T06:03:28.803Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"LFE","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lfex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-08T06:15:31.000Z","updated_at":"2021-06-08T14:26:20.000Z","dependencies_parsed_at":"2022-09-01T06:21:23.351Z","dependency_job_id":null,"html_url":"https://github.com/lfex/complex","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfex%2Fcomplex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfex%2Fcomplex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfex%2Fcomplex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfex%2Fcomplex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lfex","download_url":"https://codeload.github.com/lfex/complex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239225764,"owners_count":19603158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T15:20:20.733Z","updated_at":"2025-10-05T19:32:03.955Z","avatar_url":"https://github.com/lfex.png","language":"LFE","funding_links":[],"categories":[],"sub_categories":[],"readme":"# complex\n\n[![Build Status][travis badge]][travis] [![LFE Versions][lfe badge]][lfe] [![Erlang Versions][erlang badge]][versions] [![Tags][github tags badge]][github tags] [![Downloads][hex downloads]][hex package]\n\n*LFE support for numbers both real and imagined*\n\n[![Complex project logo][logo]][logo-large]\n\n## Table of Contents\n\n* [Introduction](#introduction-)\n* [Installation](#installation-)\n* [Usage](#usage-)\n  * [Creating Complex Numbers](#creating-complex-numbers-)\n    * [From Strings](#creating-from-strings-)\n    * [From Atoms](#creating-from-atoms-)\n  * [Convenience Functions](#convenience-functions-)\n    * [Printing](#printing-complex-numbers-)\n    * [Common Numbers](#common-numbers-)\n  * [Math](#math-)\n    * [Arithmatic](#arithmatic-)\n    * [Operations](#operations-)\n    * [Powers](#powers-)\n* [API](#api-)\n* [License](#license-)\n\n## Introduction [\u0026#x219F;](#table-of-contents)\n\nThis library provides complex number data types (LFE records for rectangular\nand polar complex numbers) as well as many mathematical operations which\nsupport the complex data type. For a full list of functions in the API,see\nthe bottom of this README file.\n\n## Installation [\u0026#x219F;](#table-of-contents)\n\nJust add it to your `rebar.config` deps:\n\n```erlang\n{deps, [\n    {complex, {git, \"https://github.com/lfex/complex.git\", {branch, \"master\"}}}\n  ]}.\n```\n\nAt this point, the complex library will be avialable in your project's dependencies.\n\n## Usage [\u0026#x219F;](#table-of-contents)\n\n### Creating Complex Numbers [\u0026#x219F;](#table-of-contents)\n\nCreate some new complex numbers using the standard rectangular coordinates:\n\n```lisp\nlfe\u003e (set z1 (complex:new 4 -2))\n#(complex 4 -2)\nlfe\u003e (set z2 (complex:new 4 2))\n#(complex 4 2)\n```\n\nCreate complex numbers using polar coordinates:\n\n```lisp\nlfe\u003e (set z3 (complex:new-polar 4 (* -0.5 (math:pi))))\n#(complex-polar 4 -1.5707963267948966)\nlfe\u003e (set z4 (complex:new-polar 4 (* 0.5 (math:pi))))\n#(complex-polar 4 1.5707963267948966)\n```\n\n#### Creating from Strings [\u0026#x219F;](#table-of-contents)\n\nYou can also create a new complex number using a string value:\n\n```lisp\nlfe\u003e (complex:new \"4-2i\")\n#(complex 4 -2)\nlfe\u003e (complex:new \"4+2i\")\n#(complex 4 2)\n```\n\nThere are rules for using complex strings, though:\n\n* there can be no spaces in the complex string\n* you must always include the real part, even if the value is zero:\n  `(complex:new \"0+2i\")`\n* the imaginary part must always include the number, even if the\n  component value is `1`: `(complex:new \"2+1i\")`\n\nOptional usage:\n\n* if the imaginary component is zero, you may leave it\n  off: `(complex:new \"2\")`\n* you may use `i`, `j`, `I`, or `J` to indicate the imaginary\n  part: `(complex:new \"-4+2j\")`\n* you may use floating point values: `(complex:new \"1.2-3.4i\")`\n* you may use scientific notation:\n  `(complex:new \"1.2e3-4.5e-6i\")`\n\n#### Creating from Atoms [\u0026#x219F;](#table-of-contents)\n\nUsing the same rules, you may use atoms to create a new complex number:\n\n```lisp\nlfe\u003e (complex:new '4-2i)\n#(complex 4 -2)\nlfe\u003e (complex:new '4.3+2.1i)\n#(complex 4.3 2.1)\nlfe\u003e (complex:new '4.3e10-2.1e-20j)\n#(complex 4.3e10 -2.1e-20)\n```\n\nHowever, do keep in mind that the use of atoms to create complex numbers\nshould not be done automatically in large numbers, or you run the risk\nof exhuasting the Erlang atom table and thus crashing your VM.\n\n### Convenience Functions [\u0026#x219F;](#table-of-contents)\n\nFor the rest of the usage, we'll just `slurp` so that the calls are easier to type:\n\n```lisp\nlfe\u003e (slurp \"src/complex.lfe\")\n#(ok complex)\n```\n\n#### Printing Complex Numbers [\u0026#x219F;](#table-of-contents)\n\nPrint the numbers we previously defined:\n\n```lisp\nlfe\u003e (format z1)\n4-2i\nok\nlfe\u003e (format z2)\n4+2i\nok\nlfe\u003e (format z3)\n0-4.0i\nok\nlfe\u003e (format z4)\n0+4.0i\nok\n```\n\nNote that `format/1` will convert a polar coordinate to rectangular; thus the\nlast two above.\n\n#### Common Numbers [\u0026#x219F;](#table-of-contents)\n\n```lisp\nlfe\u003e (one)\n#(complex 1 0)\nlfe\u003e (two)\n#(complex 2 0)\nlfe\u003e (i)\n#(complex 0 1)\nlfe\u003e (pi)\n#(complex 3.141592653589793 0)\nlfe\u003e (e)\n#(complex 2.718281828459045 0)\nlfe\u003e (-pi/2)\n#(complex -1.5707963267948966 0)\n```\n\n### Math [\u0026#x219F;](#table-of-contents)\n\n#### Arithmatic [\u0026#x219F;](#table-of-contents)\n\n```lisp\nlfe\u003e (add (complex 4 2) (i))\n#(complex 4 3)\nlfe\u003e (sub (complex 4 2) (i))\n#(complex 4 1)\nlfe\u003e (mult (complex 4 2) (i))\n#(complex -2 4)\nlfe\u003e (div (complex 4 2) (i))\n#(complex 2.0 -4.0)\n```\n\nNote that `complex/2` is an alias for `new/2`; it just looks nicer\nwhen not using the module name.\n\n#### Operations [\u0026#x219F;](#table-of-contents)\n\n```lisp\nlfe\u003e (conj z2)\n#(complex 4 -2)\nlfe\u003e (eq z1 z2)\nfalse\nlfe\u003e (eq z1 (conj z2))\ntrue\nlfe\u003e (inv z1)\n#(complex 0.2 0.1)\nlfe\u003e (inv z2)\n#(complex 0.2 -0.1)\nlfe\u003e (modulus z1)\n4.47213595499958\nlfe\u003e (modulus z1 #(complex))\n#(complex 4.47213595499958 0)\nlfe\u003e (modulus (complex-polar 4 (math:pi)))\n4\nlfe\u003e (arg (complex-polar 4 (math:pi)))\n3.141592653589793\n```\n\n```lisp\nlfe\u003e (sqrt (-one))\n#(complex 0.0 1.0)\nok\nlfe\u003e (eq (sqrt (-one)) (i))\ntrue\n```\n\n#### Powers [\u0026#x219F;](#table-of-contents)\n\nUsing exponents to demonstrate the cyclic values of the powers of *i*:\n\n```lisp\nlfe\u003e (format (pow (i) 0))\n1+0i\nok\nlfe\u003e (format (pow (i) 1))\n0+1i\nok\nlfe\u003e (format (pow (i) 2))\n-1+0i\nok\nlfe\u003e (format (pow (i) 3))\n0-1i\nok\nlfe\u003e (format (pow (i) 4))\n1+0i\nok\n```\n\nNegative powers are supported:\n\n```lisp\nlfe\u003e (pow (pi) -2)\n#(complex 0.10132118364233778 0.0)\nlfe\u003e (pow (two) -4)\n#(complex 0.0625 0.0)\n```\n\nAs are fractional powers (roots):\n\n```lisp\nlfe\u003e (pow 16 (/ 1 2))\n#(complex 4.0 0)\nlfe\u003e (pow 16 (/ 1 4))\n#(complex 2.0 0)\nlfe\u003e (pow 16 (/ 1 8))\n#(complex 1.4142135623730951 0)\n```\n\nSee the [unit tests](tests) for a greater number of examples.\n\n## API [\u0026#x219F;](#table-of-contents)\n\nThe list of functions currently supported by the complex library are as follows:\n\n```lisp\ncomplex:-2pi/0\ncomplex:-\u003eatom/1\ncomplex:-\u003estr/1\ncomplex:-i/0\ncomplex:-i/2/0\ncomplex:-one/0\ncomplex:-pi/0\ncomplex:-pi/2/0\ncomplex:-two/0\ncomplex:2pi/0\ncomplex:abs/1\ncomplex:abs/2\ncomplex:acos/1\ncomplex:acosh/1\ncomplex:acot/1\ncomplex:acoth/1\ncomplex:acsc/1\ncomplex:acsch/1\ncomplex:add/2\ncomplex:angle/1\ncomplex:arg/1\ncomplex:arg/2\ncomplex:asec/1\ncomplex:asech/1\ncomplex:asin/1\ncomplex:asinh/1\ncomplex:atan/1\ncomplex:atanh/1\ncomplex:atom-\u003e/1\ncomplex:complex/2\ncomplex:complex-polar/2\ncomplex:complex-polar?/1\ncomplex:complex?/1\ncomplex:conj/1\ncomplex:cos/1\ncomplex:cosh/1\ncomplex:cot/1\ncomplex:coth/1\ncomplex:csc/1\ncomplex:csch/1\ncomplex:distance/1\ncomplex:div/2\ncomplex:e/0\ncomplex:eeq/2\ncomplex:eq/2\ncomplex:eq/3\ncomplex:exp/1\ncomplex:i/0\ncomplex:i/2/0\ncomplex:img/1\ncomplex:inv/1\ncomplex:ln/1\ncomplex:modsq/1\ncomplex:modulus/1\ncomplex:modulus/2\ncomplex:mult/2\ncomplex:neg/1\ncomplex:new/0\ncomplex:new/1\ncomplex:new/2\ncomplex:new-polar/0\ncomplex:new-polar/1\ncomplex:new-polar/2\ncomplex:one/0\ncomplex:phase/1\ncomplex:phi/1\ncomplex:pi/0\ncomplex:pi/2/0\ncomplex:polar-\u003erect/1\ncomplex:polar-\u003erect/2\ncomplex:pow/2\ncomplex:print/1\ncomplex:r/1\ncomplex:real/1\ncomplex:rect-\u003epolar/1\ncomplex:sec/1\ncomplex:sech/1\ncomplex:sign/1\ncomplex:sin/1\ncomplex:sinh/1\ncomplex:sqrt/1\ncomplex:str-\u003e/1\ncomplex:sub/2\ncomplex:tan/1\ncomplex:tanh/1\ncomplex:two/0\n```\n\n## License [\u0026#x219F;](#table-of-contents)\n\nApache Version 2 License\n\nCopyright © 2015-2020, Duncan McGreggor \u003coubiwann@gmail.com\u003e\n\n\u003c!-- Named page links below: /--\u003e\n\n[logo]: priv/images/complex-function-crop-x250.png\n[logo-large]: priv/images/complex-function-crop-x1000.png\n[org]: https://github.com/lfex\n[github]: https://github.com/lfex/complex\n[gitlab]: https://gitlab.com/lfex/complex\n[travis]: https://travis-ci.org/lfex/complex\n[travis badge]: https://img.shields.io/travis/lfex/complex.svg\n[lfe]: https://github.com/rvirding/lfe\n[lfe badge]: https://img.shields.io/badge/lfe-1.3.0-blue.svg\n[erlang badge]: https://img.shields.io/badge/erlang-19%20to%2023-blue.svg\n[versions]: https://github.com/lfex/complex/blob/master/.travis.yml\n[github tags]: https://github.com/lfex/complex/tags\n[github tags badge]: https://img.shields.io/github/tag/lfex/complex.svg\n[github downloads]: https://img.shields.io/github/downloads/lfex/complex/total.svg\n[hex badge]: https://img.shields.io/hexpm/v/complex_math.svg?maxAge=2592000\n[hex package]: https://hex.pm/packages/complex_math\n[hex downloads]: https://img.shields.io/hexpm/dt/complex_math.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flfex%2Fcomplex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flfex%2Fcomplex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flfex%2Fcomplex/lists"}