views:

185

answers:

2

I have an urgent project which need many functions of a calculator (plus a few in-house business rule formulas). As I won't have time to re-invent the wheel so I am looking for source code directly.

Requirements:

  • BSD-like licensed (commercial use friendly, GPL won't help)
  • in c/c++ programming language
  • 32-bit CPU
  • minimum dependency on platform API/data structure
  • best with both RPN and prefix notation supported
  • emulator/simulator code also acceptable (if not impossible to add custom formula)

with following functions (from wikipedia)

  • Scientific notation for calculating large numbers
  • floating point arithmetic
  • logarithmic functions, using both base 10 and base e
  • trigonometry functions (some including hyperbolic trigonometry)
  • exponents and roots beyond the square root
  • quick access to constants such as pi and e

plus

  • hexadecimal, binary, and octal calculations, including basic Boolean math
  • fractions

optional

  • statistics and probability calculations
  • complex numbers
  • programmability
  • equation solving
+4  A: 

I did a search on sourceforge.net for "calculator" where license is "BSD License". Here are the results.

TTCalc looks like it has a lot of stuff from your list, although there are others. You could also try other licenses - Public Domain, Apache License, and MIT License are probably good as well.

Mike Pelley
thanks for the reminder of _other_ licenses, I edited my question
ohho
+1  A: 

I understand you may want one of the off-the-shelf, and maybe you can find one that is satisfactory.

This is generally considered to be a pretty easy coding exercise, to the point where it is proposed as a SO code-golf exercise., complete with a dozen solutions that almost fit your needs.

Ira Baxter
to be frank, I don't have the guts to use golf code. at least not a project for _my_ clients ;-)
ohho
Best of luck. If you can't understand one of those, I'd worry about getting an open source thingie.
Ira Baxter
my personal understanding is only one concern. an open source option comes with the benefit of "more users" (though I can't be sure how many golf code here are being used in production sites)
ohho
None are being used. The point is this is truly an easy piece of code. Whatever open source package you find is likely to be a lot more UI goo which you're going to toss than content by a lot, and you'll have to understand all that to throw the goo away. The core expression evaluator is practically nothing.
Ira Baxter
it looks to me the c golf code does not do more than + - * / ^ ( ) =
ohho
The point of these is that expression calculators are extremely easy. Given how these are put together, adding unary operators, more binary operators, special constants, etc. should be almost obvious. The "fractions" will require you to use a rationals package. Your optional part goes far beyond a "simple" calculator, Finally, you need to add your "business rule" formulas; you'll have to figure out how whatever calulator you take works to put those in.
Ira Baxter