No description
Find a file
Nicklas Sindlev Andersen 3c45228b98
Some checks failed
main / build (push) Has been cancelled
Merge pull request #36 from NicklasXYZ/main
Improvements to sequence-related functions
2024-12-18 23:40:28 +01:00
.github/workflows update workflows 2024-08-12 23:32:37 +02:00
src Implement both list & yielder-based functions for sequence-related functions. 2024-12-18 23:36:06 +01:00
test Implement both list & yielder-based functions for sequence-related functions. 2024-12-18 23:36:06 +01:00
.gitignore Initial commit 2022-12-23 15:26:58 +01:00
CODE_OF_CONDUCT.md Add CoD, codeowners + licence 2023-01-29 23:48:48 +01:00
CODEOWNERS Add CoD, codeowners + licence 2023-01-29 23:48:48 +01:00
gleam.toml Refactor 2024-12-07 23:46:49 +01:00
LICENCE Add CoD, codeowners + licence 2023-01-29 23:48:48 +01:00
manifest.toml Refactor 2024-12-07 23:46:49 +01:00
README.md Refactor 2024-12-07 23:46:49 +01:00

gleam-community/maths

Package Version Hex Docs

A basic mathematics library that contains some of the most fundamental mathematics functions and utilities.

The library supports both targets: Erlang and JavaScript.

Quickstart

import gleam/float
import gleam/yielder
import gleam_community/maths
import gleeunit/should

pub fn example() {
  // Evaluate the sine function
  let result = maths.sin(maths.pi())

  // Set the relative and absolute tolerance
  let assert Ok(absolute_tol) = float.power(10.0, -6.0)
  let relative_tol = 0.0

  // Check that the value is very close to 0.0
  // That is, if 'result' is within +/- 10^(-6)
  maths.is_close(result, 0.0, relative_tol, absolute_tol)
  |> should.be_true()

  // Find the greatest common divisor
  maths.gcd(54, 24)
  |> should.equal(6)

  // Find the minimum and maximum of a list
  maths.extrema([10.0, 3.0, 50.0, 20.0, 3.0], float.compare)
  |> should.equal(Ok(#(3.0, 50.0)))

  // Determine if a number is fractional
  maths.is_fractional(0.3333)
  |> should.equal(True)

  // Generate all k = 2 combinations of [1, 2, 3]
  let assert Ok(combinations) = maths.list_combination([1, 2, 3], 2)
  combinations
  |> yielder.to_list()
  |> should.equal([[1, 2], [1, 3], [2, 3]])

  // Compute the Cosine Similarity between two (orthogonal) vectors
  maths.cosine_similarity([#(-1.0, 1.0), #(1.0, 1.0), #(0.0, -1.0)])
  |> should.equal(Ok(0.0))
}

Installation

gleam_community packages are published to hex.pm with the prefix gleam_community_. You can add them to your Gleam projects directly:

gleam add gleam_community_maths