
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Calc is safe, simple, pure Ruby mathematical expressions evaluator (calculator) library.
Although based on Ruby 'eval', it takes special care to sanitize the expression.
Calc supports all basic mathematical operations +, -, *, / and the power function (through ** operator). Calc also supports parenthesis and nesting. Calc does NOT support advanced mathematical functions like trigonometry, logarithm, etc.
Calc plays well with Rails ActiveModel::Validations. If the supplied expression is invalid (nil, blank, or syntax error), it returns the expression itself verbatim, thus allowing to handle errors via Rails validations.
require 'calc'
Calc.evaluate( "2 + 2" ) # => 4
Calc.evaluate( "2 * (1 + 9)" ) # => 20
Calc.evaluate( "2 ** (1.0 / 2)" ) # => 1.4142135623730951 (the square of two)
Calc.evaluate( "( ( 2 - 3 ) / 13 * ( 50 + 325.843 ) ) ** 3" ) # => -53090815.704202116
gem install calc
Add the following to your Gemfile:
gem 'calc'
Then run as usual:
bundle
Calc defines a white list of characters allowed in the expression to prevent code injection attacks. All letters are outlawed as well as majority of other characters. Calc comes with tests.
Copyright (C) 2010 Piotr 'Qertoip' Włodarek. Distributed under the MIT License.
FAQs
Unknown package
We found that calc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.