{"id":17997354,"url":"https://github.com/thma/hasbigdecimal","last_synced_at":"2025-07-07T20:08:12.089Z","repository":{"id":32446318,"uuid":"121046562","full_name":"thma/HasBigDecimal","owner":"thma","description":"simple implementation of big decimals in Haskell - inspired by Java BigDecimals","archived":false,"fork":false,"pushed_at":"2022-10-08T08:49:51.000Z","size":208,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-29T22:40:27.657Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thma.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":"2018-02-10T19:24:32.000Z","updated_at":"2023-05-18T02:14:09.000Z","dependencies_parsed_at":"2022-08-07T17:30:45.269Z","dependency_job_id":null,"html_url":"https://github.com/thma/HasBigDecimal","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thma%2FHasBigDecimal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thma%2FHasBigDecimal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thma%2FHasBigDecimal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thma%2FHasBigDecimal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thma","download_url":"https://codeload.github.com/thma/HasBigDecimal/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245589254,"owners_count":20640251,"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-10-29T21:18:08.143Z","updated_at":"2025-07-07T20:08:12.082Z","avatar_url":"https://github.com/thma.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Actions Status](https://github.com/thma/HasBigDecimal/workflows/Haskell-CI/badge.svg)](https://github.com/thma/HasBigDecimal/actions)\n\n# HasBigDecimal\n\nThis module defines the type 'BigDecimal' which provides a representation of arbitrary precision decimal numbers.\n'BigDecimal' is a native Haskell implementation based on arbitrary sized 'Integer' values.\nThe implementation was inspired by Java BigDecimals. It aims to provide a simple to use API.\n\n```haskell\n-- | BigDecimal is represented by an unscaled Integer value and a Natural that defines the scale\n--   E.g.: (BigDecimal value = 1234, scale = 2) represents the decimal value 12.34.\ndata BigDecimal = BigDecimal\n  { \n    value :: Integer,  -- ^ the unscaled Integer value    \n    scale :: Natural   -- ^ the scale (i.e. the number of digits after the decimal point)\n  }\n```\n\nBigDecimal instantiates the following typeclasses:\n\n```haskell\ninstance Eq BigDecimal\ninstance Ord BigDecimal\n\ninstance Num BigDecimal\ninstance Fractional BigDecimal\ninstance Real BigDecimal\n\ninstance Read BigDecimal\ninstance Show BigDecimal\n```\n\nIt is thus possible to use all common numerical operations on operators like '+', '-', '*', '/', '^' on them.\n\n\n# Some examples from a ghci REPL\n```haskell\nimport           Data.BigDecimal\n\nmain :: IO ()\nmain = do\n  let a = read \"3.1415926\"\n      b = bigDecimal 31415926 7\n      c = 3.141592653589793238462643383279502884197 :: BigDecimal\n      d = 3.141592653589793238462643383279502884197e10 :: BigDecimal\n      e = 3.141592653589793238462643383279502884197e-10 :: BigDecimal\n      f = read \"3.141592653589793238462643383279502884197e-10\" :: BigDecimal\n\n  print $ 100 * a\n  print $ 100 * b\n  print $ a == b\n  print c\n  print d\n  print e\n  print f\n```\n\n# BigFloating\nin addition to the pretty complete BigDecimal module there is the rather scetchy BigFloating module.\nBigFloating contains a few first steps to let `BigDecimal` instantiate the `Floating` typeclass.\nAs of now it contains arbitrary precision implementations for pi (based on Chudnovskis algorithm), sqrt and nthroot (based on Newtons classic algorithm).\nAll trigonometric functions, log and exp are still missing.\nAll code contributions are most welcome!\n\nHere are some working examples:\n\n```haskell\nimport           Data.BigDecimal\nimport           Data.BigFloating\n\n-- | piChudnovsky computes pi using the Chudnovsky algorithm\nbigPi :: BigDecimal\nbigPi = piChudnovsky (DOWN, Just 100)\n\n-- in western music theory a half tone step is the twelfth root of 2\nhalfToneStep :: BigDecimal\nhalfToneStep = nthRoot 2 12 (HALF_UP, Just 50)\n\n-- take an input frequency and a number of half tone steps\n-- and return the frequency of the note that is that many half tone steps\n-- away from the input frequency\nhalfToneStepsFrom :: BigDecimal -\u003e Integer -\u003e BigDecimal\nhalfToneStepsFrom baseFrequency halfToneSteps =\n  baseFrequency * halfToneStep ^^ halfToneSteps\n\nmain :: IO ()\nmain = do\n\n  print bigPi\n\n  print $ 2 / bigPi\n\n  let r = 2\n\n  print $ r ^ 2 * pi\n\n  print $ sqrt 2\n\n  print $ sqr 2 (halfUp 3000)\n\n  print (pi :: BigFloating DOWN_100)\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthma%2Fhasbigdecimal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthma%2Fhasbigdecimal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthma%2Fhasbigdecimal/lists"}