{"id":13537663,"url":"https://github.com/eriksencosta/math-common","last_synced_at":"2025-12-25T06:45:00.380Z","repository":{"id":230264536,"uuid":"778066929","full_name":"eriksencosta/math-common","owner":"eriksencosta","description":"Math conventions to reduce boilerplate code","archived":false,"fork":false,"pushed_at":"2024-10-14T17:38:31.000Z","size":140,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"trunk","last_synced_at":"2024-11-03T02:33:06.610Z","etag":null,"topics":["kotlin","math","rounding"],"latest_commit_sha":null,"homepage":"https://blog.eriksen.com.br/opensource/math-common/","language":"Kotlin","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/eriksencosta.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-27T02:25:00.000Z","updated_at":"2024-10-14T17:38:35.000Z","dependencies_parsed_at":"2024-04-15T22:29:10.243Z","dependency_job_id":"d01d12b4-ee42-4450-90ac-f51998c7a6d7","html_url":"https://github.com/eriksencosta/math-common","commit_stats":null,"previous_names":["eriksencosta/math-common"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eriksencosta%2Fmath-common","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eriksencosta%2Fmath-common/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eriksencosta%2Fmath-common/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eriksencosta%2Fmath-common/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eriksencosta","download_url":"https://codeload.github.com/eriksencosta/math-common/tar.gz/refs/heads/trunk","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243136280,"owners_count":20241988,"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":["kotlin","math","rounding"],"created_at":"2024-08-01T09:01:01.786Z","updated_at":"2025-12-25T06:45:00.374Z","avatar_url":"https://github.com/eriksencosta.png","language":"Kotlin","readme":"# Math Common\n\n[![Codacy grade](https://img.shields.io/codacy/grade/78b28d3fdf8f4a869b2222b623eb0ed0)](https://app.codacy.com/gh/eriksencosta/math-common/dashboard)\n[![Codacy coverage](https://img.shields.io/codacy/coverage/78b28d3fdf8f4a869b2222b623eb0ed0)](https://app.codacy.com/gh/eriksencosta/math-common/coverage)\n\nMath conventions to reduce boilerplate code.\n\n## Installation\n\nAdd Math Common to your Gradle build script:\n\n```kotlin\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    implementation(\"com.eriksencosta.math:common:0.3.0\")\n}\n```\n\nIf you're using Maven, add to your POM xml file:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.eriksencosta.math\u003c/groupId\u003e\n    \u003cartifactId\u003ecommon\u003c/artifactId\u003e\n    \u003cversion\u003e0.3.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Usage\n\n### Rounding\n\nThe library provides the `Rounding` [strategy](https://refactoring.guru/design-patterns/strategy) to make rounding\neasier:\n\n```kotlin\n1.25.round(1) // 1.3\n```\n\nBy default, the [RoundingMode.HALF_EVEN](https://docs.oracle.com/javase/8/docs/api/java/math/RoundingMode.html#HALF_EVEN) is\nused for rounding (it is the rounding logic commonly taught at school). If you want to use a different mode, create a\n`Rounding` and use it:\n\n```kotlin\nimport java.math.RoundingMode\n\nval rounding = Rounding.to(2, RoundingMode.FLOOR)\n\nrounding.round(1.257) // 1.25\nrounding.round(1.253) // 1.25\n\n// Alternatively:\n\n1.257.round(rounding) // 1.25\n1.253.round(rounding) // 1.25\n```\n\nIf you want to round the result of a calculation, use the overloaded `round()` method which accepts a function as\nparameter:\n\n```kotlin\nRounding.to(2).round { 3.14159 * 10.0.squared() } // 314.16\n```\n\nAlternatively:\n\n```kotlin\n{ 3.14159 * 10.0.squared() }.round(2) // 314.16\n```\n\n### Exponentiation\n\nThe extension functions `squared` and `cubed` are available for `BigDecimal`, `Double`, `Float`, `Long`, and `Int`:\n\n```kotlin\n2.squared() // 4\n2.0.cubed() // 8.0\n```\n\n## API documentation\n\nRead the [API documentation](https://blog.eriksen.com.br/opensource/math-common/) for further details.\n\n## License\n\n[The Apache Software License, Version 2.0](https://choosealicense.com/licenses/apache/)\n","funding_links":[],"categories":["Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feriksencosta%2Fmath-common","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feriksencosta%2Fmath-common","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feriksencosta%2Fmath-common/lists"}