Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More math functions #219

Merged
merged 14 commits into from
Dec 8, 2023
Merged

More math functions #219

merged 14 commits into from
Dec 8, 2023

Conversation

JeanJPNM
Copy link
Collaborator

@JeanJPNM JeanJPNM commented Dec 7, 2023

Adds custom implementations for the following math functions:

  • Math.sign
    Math.sign = (x: number) => {
      return (x > 0) - (x < 0);
    };
  • Math.round
    Math.round = (x: number) => {
      return Math.floor(x + 0.5);
    };
  • Math.trunc
    Math.trunc = (x: number) => {
      return x - (x % 1);
    };
  • Math.exp
    Math.exp = (x: number) => {
      return Math.pow(Math.E, x);
    };
  • Math.expm1
    Math.expm1 = (x: number) => {
      return Math.exp(x) - 1;
    };
  • Math.cosh
    Math.cosh = (degrees: number) => {
      const x = degrees * Math.degToRad;
      return (Math.exp(x) + Math.exp(-x)) / 2;
    };
  • Math.acosh
    Math.acosh = (x: number) => {
      return Math.log(x + Math.sqrt(x ** 2 - 1)) * Math.radToDeg;
    };
  • Math.sinh
    Math.sinh = (: number) => {
      const x = degrees * Math.degToRad;
      return (Math.exp(x) - Math.exp(-x)) / 2;
    };
  • Math.asinh
    Math.asinh = (x: number) => {
      return Math.log(x + Math.sqrt(x ** 2 + 1)) * Math.radToDeg;
    };
  • Math.tanh
    Math.tanh = (degrees: number) => {
      const x = degrees * Math.degToRad;
      return (Math.exp(x) - Math.exp(-x)) / (Math.exp(x) + Math.exp(-x));
    };
  • Math.atanh
    Math.atanh = (x: number) => {
      return (Math.log((1 + x) / (1 - x)) / 2) * Math.radToDeg;
    };

For the sake of consistency with the mlog trigonometric functions, these ones also use degrees instead of radians.

Copy link

netlify bot commented Dec 7, 2023

Deploy Preview for mlogjs ready!

Name Link
🔨 Latest commit d4d65d0
🔍 Latest deploy log https://app.netlify.com/sites/mlogjs/deploys/6571ce32926268000897568d
😎 Deploy Preview https://deploy-preview-219--mlogjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@JeanJPNM JeanJPNM merged commit 2a3cf5a into main Dec 8, 2023
6 checks passed
@JeanJPNM JeanJPNM deleted the more-math-functions branch December 8, 2023 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant