2023-01-04 19:39:01 +00:00
|
|
|
# gleam-community/maths
|
2022-12-23 14:26:58 +00:00
|
|
|
|
2023-01-04 19:39:01 +00:00
|
|
|
[](https://hex.pm/packages/gleam_community_maths)
|
|
|
|
[](https://hexdocs.pm/gleam_community_maths/)
|
2022-12-23 14:26:58 +00:00
|
|
|
|
2023-01-04 19:39:01 +00:00
|
|
|
A basic mathematics library that contains some of the most fundamental mathematics functions and utilities.
|
2022-12-23 14:26:58 +00:00
|
|
|
|
2023-01-04 19:39:01 +00:00
|
|
|
The library supports both targets: Erlang and JavaScript.
|
|
|
|
|
|
|
|
## Quickstart
|
|
|
|
|
|
|
|
```gleam
|
2023-09-17 12:15:10 +00:00
|
|
|
import gleam_community/maths/elementary
|
|
|
|
import gleam_community/maths/arithmetics
|
|
|
|
import gleam_community/maths/piecewise
|
|
|
|
import gleam_community/maths/tests
|
|
|
|
import gleam/float
|
2023-01-04 19:39:01 +00:00
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
// Evaluate the sine function
|
2023-09-17 12:20:47 +00:00
|
|
|
elementary.sin(elementary.pi())
|
2023-01-04 19:39:01 +00:00
|
|
|
// Returns Float: 0.0
|
|
|
|
|
|
|
|
// Find the greatest common divisor
|
2023-09-17 12:15:10 +00:00
|
|
|
arithmetics.gcd(54, 24)
|
2023-09-17 12:16:36 +00:00
|
|
|
// Returns Int: 6
|
2023-01-04 19:39:01 +00:00
|
|
|
|
|
|
|
// Find the minimum and maximum of a list
|
2023-09-17 12:15:10 +00:00
|
|
|
piecewise.extrema([10.0, 3.0, 50.0, 20.0, 3.0], float.compare)
|
2023-01-04 19:39:01 +00:00
|
|
|
// Returns Tuple: Ok(#(3.0, 50.0))
|
|
|
|
|
2023-01-22 21:39:10 +00:00
|
|
|
// Find the list indices of the smallest value
|
2023-09-17 12:15:10 +00:00
|
|
|
piecewise.arg_minimum([10, 3, 50, 20, 3], float.compare)
|
2023-09-17 12:16:36 +00:00
|
|
|
// Returns List: Ok([1, 4])
|
2023-09-17 12:15:10 +00:00
|
|
|
|
2023-09-17 12:15:35 +00:00
|
|
|
// Determine if a number is fractional
|
2023-09-17 12:15:10 +00:00
|
|
|
tests.is_fractional(0.3333)
|
2023-09-17 12:16:36 +00:00
|
|
|
// Returns Bool: True
|
2023-09-17 12:15:10 +00:00
|
|
|
|
|
|
|
// Determine if 28 is a power of 3
|
|
|
|
tests.is_power(28, 3)
|
|
|
|
// Returns Bool: False
|
|
|
|
|
|
|
|
// Generate all k = 1 combinations of [1, 2]
|
2023-09-17 12:16:10 +00:00
|
|
|
combinatorics.list_combination([1, 2], 1)
|
2023-09-17 12:16:36 +00:00
|
|
|
// Returns List: Ok([[1], [2]])
|
2023-01-04 19:39:01 +00:00
|
|
|
}
|
2022-12-23 14:26:58 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
2023-01-04 19:39:01 +00:00
|
|
|
`gleam_community` packages are published to [hex.pm](https://hex.pm/packages/gleam_community_maths)
|
|
|
|
with the prefix `gleam_community_`. You can add them to your Gleam projects directly:
|
2022-12-23 14:26:58 +00:00
|
|
|
|
|
|
|
```sh
|
2023-01-04 19:39:01 +00:00
|
|
|
gleam add gleam_community_maths
|
2023-01-22 21:39:10 +00:00
|
|
|
```
|