Giter Club home page Giter Club logo

swift-prime's Introduction

OBSOLETED BY

PONS, Protocol-Oriented Number System in Pure Swift.

It has all functionality of swift-prime plus BigInt support.

build status

swift-prime

Prime number extension in Pure Swift

SYNOPSIS

import Prime                            // not needed if you are using prime.swift directly
2.isPrime                               // true
42.isPrime                              // false
0x7FFFffff.isPrime                      // true (M31)
0.nextPrime                             // 2
Int.max.prevPrime                       // 9223372036854775783 on OS X
Int.Prime.within(0..<100)               // [2, 3, 5, 7, ... 97]
Int.Prime.within(Int.max-100..<Int.max) // [9223372036854775783]
Int.max.primeFactors                    // [7, 7, 73, 127, 337, 92737, 649657]

Requirement

Swift 2.x, both Xcode 7 and Linux.

  • It emits warings on Swift 2.2 but works okay.

USAGE

In your project

Just add prime.swift to it.

Workspace

Browse all the playgrounds and the project via Prime.xcworkspace.

Playground

Just open the playground file of your OS of choice and enjoy. OSX most detaild. iOS and tvOS just for testing purpurse.

REPL

just make repl.

CAVEAT: you still have to import Prime in REPL.

  1> 42.isPrime
repl.swift:1:1: error: value of type 'Int' has no member 'isPrime'
42.isPrime
^~ ~~~~~~~

  1> import Prime
  2> 42.isPrime 
$R0: Bool = false
  3>

OS X

git clone https://github.com/dankogai/swift-prime.git
cd swift-prime
make repl

Linux

git clone https://github.com/dankogai/swift-prime.git
cd swift-prime
make SWIFTPATH=${YOUR_SWIFT_PATH} repl # ${YOUR_SWIFT_PATH}=~/swift/usr/bin in my case

CAVEAT

It used to depend on 128-bit arithmetics bridged to C but it is written to be C-Free. In exchange it is a little slower.

swift-prime's People

Contributors

dankogai avatar tiza59 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.