Skip navigation

Category Archives: Cocoa

Offtonic Pell Solver has been released!

Tired of the endless waiting?  No?  Well, if you had been, you could have stopped waiting now, provided you have OS X 10.7 (Lion).  This initial release solves a general Pell-type equation by finding all solutions when there are finitely many, and when there aren’t, it finds all of the fundamental solutions and generates an arbitrary number of new solutions from those.

Currently it only works for parameters up to 2^31 (and this is not changing anytime soon due to the difficulty in factoring such large numbers), and the solutions can go up to 2^63.  This latter limit will change to arbitrary size once I implement a large numbers library and rewrite my Pell solver to use it.  That’s the next version.

Read More »

My Pell solver is only supposed to solve Diophantine equations, which are equations with integers. I have some text fields for the parameters, and NSString deals with this just fine: to get the integer value from a text field, simply do:

int n = [[nField stringValue] intValue];

This assumes that you have an IBOutlet NSTextField *nField to read from. This works pretty well; the parser stops when it encounters something it doesn’t like, so if you type in “foo”, n will just be 0. You won’t get errors. However, it doesn’t look so good for the user when this happens. You can use a number formatter to make sure the user can only type in valid integers. Here is a complete implementation of an integer formatter:

Read More »

I have recently had the misfortune of trying to write an equation programmatically, and in this tutorial, I will allow you to share my misfortune.  I say “misfortune”, but really, I should just have used a text editor and made an image; however, I felt that I should at least figure out how to do it.  The result, unlike the code, was pretty:

Pell-Type Equation, Pretty

The generic Pell-type equation, pretty-printed

The idea here was to use this equation as a header label for my Pell solver (upcoming).  It’s just static text against the default background of an Aqua window, like a Label in Interface Builder, except that the Label object has fixed height and therefore can’t hold this enlarged text with superscripts, so instead, I made a custom NSView subclass to draw it.  (There are probably better options, like multi-line labels.)  By the way, note that I’m using ARC, so if you’re not using it for whatever reason, you’ll have to handle the memory management yourself. The basic code for the subclass:

Read More »