New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

smath

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smath

Small math function library

  • 1.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
198
decreased by-7.48%
Maintainers
1
Weekly downloads
 
Created
Source

Home | Docs | GitHub | npm | Changelog | YouTube | Small math function library

NPM Downloads NPM Version Relative date GitHub watchers GitHub forks GitHub Repo stars

Installation

smath can be installed from the official npm package repository. It is highly recommended to install the latest version, which is installed by default with the following command.

npm i smath@1.3.0

Bugs and Requests

Is there a way we can make smath better? Please report all bugs, issues, and new feature requests to the issues page in the official repository. For critical security issues, please send an email to smath@nicolasventura.com.

Contribute

Thank you for your interest in contributing to smath! smath is an open source software package maintained by Nicolas Ventura (@nicfv) and built by users like you! You are allowed to fork the repository as permitted by the MIT License terms. Contributions are welcome by submitting a pull request. Please follow the existing code styling if submitting a pull request. Thank you for your consideration!

Getting Started

Similar to JavaScript's builtin Math object, SMath exports one global object with several math-related helper functions. There is no need to instantiate the class, just call functions directly. See the examples below to get started using SMath!

Example

Here are a few examples written in JavaScript for a quick start into SMath.

JavaScript Math Oddities

import { SMath } from 'smath';

// Determine the value of 0.1 + 0.2 using vanilla JavaScript and SMath
console.log('0.1 + 0.2 == 0.3 is ' + (0.1 + 0.2 == 0.3));
console.log('SMath.approx(0.1 + 0.2, 0.3) is ' + SMath.approx(0.1 + 0.2, 0.3));
0.1 + 0.2 == 0.3 is false
SMath.approx(0.1 + 0.2, 0.3) is true

Temperature Conversion

A temperature conversion tool using SMath.translate to convert units. The translation uses freezing and boiling points for 2 unit systems to linearly interpolate between them.

import { SMath } from 'smath';

// Water always freezes at the
// same temperature, but the
// units might be different.
// Define some constants to
// create two number ranges.
const C_Freeze = 0,
    C_Boil = 100,
    F_Freeze = 32,
    F_Boil = 212;

// Use the `SMath` class to
// generate an array of five
// linearly spaced temperature
// values from 0 to 20.
const C = SMath.linspace(0, 20, 5);

// Use the `SMath` class to linearly
// interpolate the temperature in the
// C number range to a temperature
// in the F number range.
const F = C.map(c => SMath.translate(c, C_Freeze, C_Boil, F_Freeze, F_Boil));

// Print out each temperature
// in both units of C and F.
for (let i = 0; i < C.length; i++) {
    console.log(C[i].toFixed() + 'C is ' + F[i].toFixed() + 'F')
}
0C is 32F
5C is 41F
10C is 50F
15C is 59F
20C is 68F

Keywords

FAQs

Package last updated on 22 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc