Sey is a powerful math interpreter with infinite-precision.

Overview

The word Sey on a blue background

Sey

Tests Formats Version Total Downloads License

Sey, pronounce say, is a powerful math interpreter with infinite-precision.

Installation

Requires PHP 8.0.0+ and the bcmath extension

You can install the package via composer:

composer require felixdorn/sey

Usage

Sey::parse('(0.5 + 0.5) / 3)'); // 0.3333333333333333
// or
sey('a / b', ['a' => 1, 'b' => 2]); // 0.5

Precision

By default, the maximum floating precision is 16.

You may change it:

\Felix\Sey\Sey:precision(32);

Syntax

It's just math.

1 + 2
2 - 3
3 * 4
4 / 5
5 % 6
6 ^ 7
7 * (8 + 9)
sqrt(10)
powmod(11)
11(12 - 13)
(14 + 15)^16
!(5)
pi()

Variables

You can not define variables in your code but you can pass them at compile-time.

Sey::parse('2 * r * pi', [
    'r' => 10,
    'pi' => 3.1415
]);

Functions

  • sqrt: bcsqrt

  • powmod: bcpowmod

  • pi(): custom bcpi function

    This function returns pi with your defined precision up to 999 digits.

  • !(n): custom bcfact function

    This computes n!, if you need to do it really quickly, you should probably use a lookup table.

Custom functions

You can override built-ins functions.

Sey::define('!', function (int $n, /* as many arguments as you want */) {
    return $factorials[$n] ?? bcfact($n);
});

The function name must match the following regex [a-z_A-Z!]+[a-z_A-Z0-9]*.

So, first character must be a letter or ! followed by any number of letters or numbers.

Tests

composer test

sey was created by Félix Dorn under the MIT license.

You might also like...
Provides powerful menu editor to replace category based menus in Magento 2

Magento 2 Menu Provides powerful menu editor to replace category based menus in Magento 2. Setup Create new menu in the admin area Content Elements

Magento 2 Blog Extension - FREE, fully featured, powerful Blog solution for your online store!

Blog MX | Magento 2 Blog Module by Mirasvit FREE, fully featured, powerful Blog solution for your online store! Magento 2 Blog MX allows you to open a

A powerful music API framework to accelerate your development
A powerful music API framework to accelerate your development

🍰 Wow, such a powerful music API framework Introduction A powerful music API framework to accelerate your development Elegant - Easy to use, a standa

Sentrifugo is a FREE and powerful Human Resource Management System (HRMS) that can be easily configured to meet your organizational needs.

Sentrifugo Sentrifugo is a free and powerful new-age Human Resource Management System that can be easily configured to adapt to your organizational pr

Yclas Self Hosted is a powerful script that can transform any domain into a fully customizable classifieds site within a few seconds.

Yclas 4.4.0. Description Yclas self-hosted is a powerful script that can transform any domain into a fully customizable classifieds site within a few

Orangescrum is a simple yet powerful free and open source project management software that helps team to organize their tasks, projects and deliver more.
Orangescrum is a simple yet powerful free and open source project management software that helps team to organize their tasks, projects and deliver more.

Free, open source Project Management software Introduction Orangescrum is the simple yet powerful free and open source project management software tha

Powerful land plugin, based on PMMP.

iLand Powerful land plugin, based on PMMP Features Land management with Form UI The border of the selected land Custom land settings Customize the per

A powerful and pretty replacement for PHP's var_export()

Brick\VarExporter A powerful and pretty replacement for PHP's var_export(). Introduction PHP's var_export() function is a handy way to export a variab

NamelessMC is a free, easy to use & powerful website software for your Minecraft server, which includes a large range of features.
NamelessMC is a free, easy to use & powerful website software for your Minecraft server, which includes a large range of features.

NamelessMC is a free, easy to use & powerful website software for your Minecraft server, which includes a large range of features

Releases(1.0.0)
Owner
Félix Dorn
Félix Dorn
The plugin allows to execute math operations in the server or console.

General The plugin allows to execute math operations in the server or console with /calculator command Arithmetic Operators List of supported arithmet

NhanAZ's PocketMine-MP Plugins 3 Oct 20, 2022
Lambda calculus interpreter in PHP.

lambda-php Lambda calculus interpreter in PHP. Lambda calculus Lambda calculus is a very minimal programming language that was invented in 1936 by Alo

Igor 22 Feb 28, 2022
The PHP Interpreter

The PHP Interpreter PHP is a popular general-purpose scripting language that is especially suited to web development. Fast, flexible and pragmatic, PH

php.net 34.8k Dec 28, 2022
Analyzer of PHP code to search issues with deprecated functionality in newer interpreter versions.

PhpDeprecationDetector PhpDeprecationDetector - analyzer of PHP code to search usages of deprecated functionality in newer interpreter versions - depr

Sergey 312 Dec 26, 2022
Analyzer of PHP code to search issues with deprecated functionality in newer interpreter versions.

PhpDeprecationDetector PhpDeprecationDetector - analyzer of PHP code to search usages of deprecated functionality in newer interpreter versions - depr

Sergey 312 Dec 26, 2022
The new, most powerful Comic Reader ever created by the human race. Reworked by an Otaku.

FoOlSlideX The new, most powerful Comic Reader ever created by the human race. Reworked by an Otaku. Requirements PHP greater than 7.0 and everything

saintly2k 21 Dec 21, 2022
Powerful and flexible component for building site breadcrumbs.

Phalcon Breadcrumbs Phalcon Breadcrumbs is a powerful and flexible component for building site breadcrumbs. You can adapt it to your own needs or impr

Serghei Iakovlev 40 Nov 5, 2022
A powerful debug and profilers tool for the Phalcon Framework

Phalcon Debugbar Integrates PHP Debug Bar with Phalcon Framework. 中文说明 Features Normal request capturing Ajax request capturing Redirect request chain

Yajie Zhu 162 Oct 7, 2022
A library of powerful code snippets to help you get the job done with Gravity Forms and Gravity Perks.

Gravity Wiz Snippet Library Gravity Wiz is creating the most comprehensive library of snippets for Gravity Forms ever. We'll be consistently moving ou

Gravity Wiz 151 Dec 27, 2022
The fastest way to make a powerful JSON:API compatible Rest API with Laravel.

The first fully customizable Laravel JSON:API builder. "CRUD" and protect your resources with 0 (zero) extra line of code. Installation You can instal

BinarCode 394 Dec 23, 2022