Skip to content

Instantly share code, notes, and snippets.

View KatkayApps's full-sized avatar

Magno Urbano KatkayApps

View GitHub Profile
@kieranb662
kieranb662 / SwiftEquationSolvers.md
Last active March 13, 2023 18:01
[Polynomial Solvers] A set of polynomial equation solvers written in Swift. #Math

Swift Equation Solvers

Most equations need to be solved numerically since no close-form expression representing their solutions can be obtained. For polynomial equations of order 1, 2, 3, 4 exact solutions can be obtained. I have created a series of solvers up to a cubic solver, that can be used to obtain most exact solutions. Of course with floating point errors, not everything is going to come out looking clean. To be able to handle complex numbers I made a simplified version of a complex number without all the mathematical operations.

If you call the cubicSolve function with a = 0 then the solver falls back on the quadratic solver, the quadratic solver will fallback on the linear solver and linear solver will return an empty array(Thanks for catching that u\korbonix).

Example Usage

@nielsbot
nielsbot / MemoryMappedDataConsumer.h
Last active August 8, 2018 01:13
memory mapped core graphics data consumer for writing PDFs
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
@interface MemoryMappedDataConsumer : NSObject
@property ( nonatomic, readonly ) size_t size ;
@property ( nonatomic, readonly ) size_t capacity ;
@property ( nonatomic, readonly ) CGDataConsumerRef CGDataConsumer ;
@property ( nonatomic, readonly, copy ) NSURL * url ;