Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

quick-is-prime

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quick-is-prime

Test if a number is prime in constant time, using a cached Sieve of Eratosthenes.

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
344
decreased by-90.43%
Maintainers
1
Weekly downloads
 
Created
Source

quick-is-prime

NPM Version

Test if a number is prime in constant time, using a cached Sieve of Eratosthenes. This is especially helpful to test many numbers' primality.

Install

$ npm install quick-is-prime
var isPrime = require('quick-is-prime');

Usage

// Simple examples
console.log(isPrime(47)); // true
console.log(isPrime(48)); // false
console.log(isPrime(61)); // true
console.log(isPrime(100)); // false

// More challenging examples
console.log(isPrime(9998903)) // true, only takes 1.5 seconds
console.log(isPrime(9893899)) // true, adds no extra calculation time

This module uses a cached Sieve of Eratosthenes for constant time lookup. A new one will be automatically generated if the number you're testing is larger than the currently cached sieve's upper bound.

For best results, check primes highest to lowest. Or alternatively, if you know what the upper bound will be, just check that first to not be concerned with the order.

Keywords

FAQs

Package last updated on 02 Sep 2015

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