SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,026
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)

    Anyone know a reliable abritrary precision math lib?

    Basic math in javascript can be a PITA once you move to arbritary precision (usually, but not always, currencty calculations). I thought I found a solution

    http://sourceforge.net/projects/bcmath-js/

    This is an implmentation of PHP's bcmath library. HOWEVER - I stumbled on a test case where it flat out didn't work and so had to roll a specific implementation solution to get my project work done.

    Does anyone know of a lib out there that actually works? If not I suppose I'll take this sourceforge project which *mostly* works and debug it. From the looks of the source code the original author just transliterated the original C code, so he's made a mistake somewhere along the line.

    The bad test case is in my thumbs down comment.

  2. #2
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,026
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    bump.

    Anyone?

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    javascript just doesn't do maths very well, at all. Do not rely on it for that, use a server-side solution instead if you require precision.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,026
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    No language does floating point math very well. That's why abritary precision libraries exist in the first place. Since I'm asking whether such a library exists it should stand to reason that I well aware of the limitations of raw javascript for doing math.

    That said, I was wondering if anyone had tackled the problem. I was looking for a solution - not an excuse and certainly not a 'do it server side' response.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •