GithubHelp home page GithubHelp logo

qdecimal's Introduction

QDecimal Library

The QDecimal is a thin layer around IBM's decNumber library which implements the General Decimal Arithmetic Specification in ANSI C.[1] This specification defines a decimal arithmetic which meets the requirements of commercial, financial, and human-oriented applications. It also matches the decimal arithmetic in the IEEE 754 Standard for Floating Point Arithmetic. The decNumber library also matches the decimal arithmetic in the IEEE 754 Standard for Floating Point Arithmetic.

The QDecimal/decNumberlibrary,[2] fully implements the specification, and hence supports integer, fixed-point, and floating-point decimal numbers directly, including infinite, NaN (Not a Number), and subnormal values. Both arbitrary-precision and fixed-size representations are supported.

The aim of the QDecimal library is to extend decNumber functionality to C++ language and Qt framework by using idioms, tecniques and best practices in both tecnologies. For instance, inline functions are used heavily to aid optimization, operator overloading and conversion operators are defined to aid type casting in between the types defined by QDecimal. Further these types are integrated with Qt object model by introducing them to Qt meta type system.

Following classes are defined by QDecimal library:

QDecNumber (based on decNumber):

decNumber module uses an arbitrary-precision decimal number representation designed for efficient computation in software and implements the arithmetic and logical operations, together with a number of conversions and utilities. Once a number is held as a decNumber, no further conversions are necessary to carry out arithmetic. The decNumber representation is variable-length and machine-dependent (for example, it contains integers which may be big-endian or little-endian). QDecNumber encapsulates decNumber and reimplements global functions that operates upon decNumber as member functions with the same name.

QDecContext (based on decContext):

Most functions in the decNumber module take as an argument a decContext structure, which provides the context for operations (precision, rounding mode, etc.) and also controls the handling of exceptional conditions (corresponding to the flags and trap enablers in a hardware floating-point implementation).

QDecSingle (based on decSingle/decimal32):

decimal32 is a 32-bit decimal floating-point representation which provides 7 decimal digits of precision in a compressed format. decSingle module provides the functions for the decimal32 format; this format is intended for storage and interchange only and so the module provides utilities and conversions but no arithmetic functions. QDecSingle encapsulates decSingle and provides decNumber library functions that operates upon decSingle as member functions with the same name.

QDecDouble (based on decDouble/decimal64):

decimal64 is a 64-bit decimal floating-point representation which provides 16 decimal digits of precision in a compressed format. decDouble module provides the functions for the decimal64 format; this format is an IEEE 754 basic format and so a full set of arithmetic and other functions is included. QDecDouble encapsulates decDouble and provides decNumber library functions that operates upon decDouble as member functions with the same name.

QDecQuad (based on decQuad/decimal128):

decimal128 is a 128-bit decimal floating-point representation which provides 34 decimal digits of precision in a compressed format. decQuad module provides the functions for the decimal128 format; this format is an IEEE 754 basic format; it contains the same set of functions as decDouble. QDecQuad encapsulates decQuad and provides decNumber library functions that operates upon decQuad as member functions with the same name.

QDecPacked (based on decPacked):

The decPacked format is the classic packed decimal format implemented by IBM S/360 and later machines, where each digit is encoded as a 4-bit binary sequence (BCD) and a number is ended by a 4-bit sign indicator. The decPacked module accepts variable lengths, allowing for very large numbers (up to a billion digits), and also allows the specification of a scale. QDecPacked augments decPacked by encapsulating reference counted byte array and scale of the decimal point as members variables, thus, freeing up user of this class from memory management and keeping track of scale value.

License

QDecimal is under the terms of the LGPL v2.1. decNumber is under the terms of ICU v1.8.1 See COPYRIGHT file for terms of the these licenses.

Platforms

QDecimal should be usable in all platforms that Qt supports. We regularly test on following platforms: Solaris 11 x86 (sun studio 12.5) Linux (Ubuntu x64 - gcc) Linux (Ubuntu x86 - gcc) Windows XP (msvc 2012)

Installation

Read INSTALL.txt to build and install QDecimal.

Copyright

Copyright (C) 2012-16 Semih Cemiloglu

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details (COPYRIGHT.txt).

Credits

We are grateful to Mike Cowlishaw et al. from IBM for making decNumber package available. Mr. Cowlishaw has kindly helped while making QDecimal production ready.

References

  1. General Decimal Arithmetic Specification: http://speleotrove.com/decimal/decarith.html

  2. The decNumber Library: http://speleotrove.com/decimal/decnumber.html

  3. General Decimal Arithmetic: http://speleotrove.com/decimal/

qdecimal's People

Contributors

dalins avatar semihc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

qdecimal's Issues

mingw32-make fails to compile the code

What steps will reproduce the problem?
1. Qmake -r
2. mingw32-make


What is the expected output? What do you see instead?
Compiled library

What version of the product are you using? On what operating system?
QT4.8 command prompt

Please provide any additional information below.

g++: /Zc:forScope: No such file or directory
g++: /Zc:wchar_t: No such file or directory
g++: /RTC1: No such file or directory
mingw32-make[2]: *** [debug/QDecContext.o] Error 1
mingw32-make[2]: Leaving directory `D:/Lähdekoodeja/qdecimal/src'
mingw32-make[1]: *** [debug] Error 2
mingw32-make[1]: Leaving directory `D:/Lähdekoodeja/qdecimal/src'
mingw32-make: *** [sub-src-make_default-ordered] Error 2

Original issue reported on code.google.com by [email protected] on 14 Apr 2014 at 7:10

An "unused parameters" warning

When compiling Main.cc, `gcc` emits a warning about
    void MessageOutput(QtMsgType type, const QMessageLogContext &context,
                        const QString &msg)
and its variable "context" that is never used. 

That puzzles the developers ("A warning?" "What's happening?" "Is QDecimal well 
done?" "Should I solve it?" "Can I solve it?" "Should I file a bug?"). I read 
<http://dbp-consulting.com/tutorials/SuppressingGCCWarnings.html> and added 
three "pragmas" in my local QDecimal copy, this way:

    [...]
    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wunused-parameter"
    void MessageOutput(QtMsgType type, const QMessageLogContext &contexte,
                        const QString &msg)
    {

    QByteArray lmsg = msg.toLocal8Bit();
    const char* cmsg = lmsg.constData();
    switch (type) {
        case QtDebugMsg:
        fprintf(stderr, "%s\n", cmsg);
        break;
        case QtWarningMsg:
        fprintf(stderr, "Warn: %s\n", cmsg);
        break;
        case QtCriticalMsg:
        fprintf(stderr, "Critical: %s\n", cmsg);
        break;
        case QtFatalMsg:
        fprintf(stderr, "Fatal: %s\n", cmsg);
        abort();
    }
    }
    #pragma GCC diagnostic pop
    [...]

and this way `gcc` doesn't warn about "unused parameters", but probably you'll 
have a better solution to avoid warning developers (`gcc` ones, at least).

Thanks for QDecimal! 

Original issue reported on code.google.com by [email protected] on 10 Aug 2013 at 5:30

A comment maybe it's not right

In
     int QDecNumberTests::opTest(const QStringList& tokens)    
it says
    /* Uncomment to receive more information about passing test cases: */
but it seems there is nothing to uncomment. Is this way?    

Thanks for QDecimal! 

Original issue reported on code.google.com by [email protected] on 10 Aug 2013 at 5:26

Can't Compile under Microsoft Visual Studio Express 2012 for Windows De3sktop

What steps will reproduce the problem?
1. Type nmake in any directory and receive error msg
"NMAKE : fatal error U1064: MAKEFILE not found and no target specified
Stop."
2. Type nmake *.pri or *.pro and all one receives is errors,
generally of the form "Too many names to left of =" wherever a +=
token appears.

What is the expected output? What do you see instead?
Trying to compile under MS VCC; nothing happens.

What version of the product are you using? 
Product: Microsoft Visual Studio Express 2012 for Windows Desktop
O/S: Windows 8

Please provide any additional information below.
In trying to compile "Example 1" under MS Viual Studio Express 2012 I get these 
5 errors:
Error   14  error LNK2001: unresolved external symbol "struct decContext * __cdecl 
decContextDefault(struct decContext *,int)" 
(?decContextDefault@@YAPAUdecContext@@PAU1@H@Z) 

Error   15  error LNK2001: unresolved external symbol "struct decNumber * __cdecl 
decNumberFromString(struct decNumber *,char const *,struct decContext *)" 
(?decNumberFromString@@YAPAUdecNumber@@PAU1@PBDPAUdecContext@@@Z)

Error   16  error LNK2001: unresolved external symbol "struct decNumber * __cdecl 
decNumberAdd(struct decNumber *,struct decNumber const *,struct decNumber const 
*,struct decContext *)" 
(?decNumberAdd@@YAPAUdecNumber@@PAU1@PBU1@1PAUdecContext@@@Z)

Error   17  error LNK2001: unresolved external symbol "char * __cdecl 
decNumberToString(struct decNumber const *,char *)" 
(?decNumberToString@@YAPADPBUdecNumber@@PAD@Z)

Error   18  error LNK1120: 4 unresolved externals

Original issue reported on code.google.com by [email protected] on 24 Jul 2013 at 10:07

Rounding Problem

Hello
I got the following problem:
I coudent figure out how to round after a callculation with the QDecDouble Type.
This is my code:
QDecDouble test(12.0003); QDecContext con; con.setDigits(4); con.setRound(DEC_ROUND_HALF_UP); test = test.add(QDecDouble(12.0003),&con); //result of the calculation is 24.0006, expectet result after rounding is 24.0010 but result still the same (24.0006)

i don't see the problem.
Thx for the help its very appriciatet and thx very mutch for QDecimal.

Regards Sascha

QDecNumber fails to construct value of DBL_MAX or DBL_MIN

What steps will reproduce the problem?
1. Attempt to instantiate a QDecNumber object from DBL_MAX double value.

QDecNumber decNum(DBL_MAX);

2. Compile and run program.

What is the expected output?

1.7976931348623158e+308

What do you see instead?

Program crashes.

What version of the product are you using? On what operating system?

1.0.0

Please provide any additional information below.

The problem stems from the fact that MaxStrSize is too small to accommodate all 
representable doubles in the 'f' format specified in sprintf(str,'%f',d) in 
fromDouble.  Changing the format specifier to '%.16e' seems to resolve the 
issue, the only downside being the forced precision of 16 decimal digits when 
that might not always be the desired precision.

Original issue reported on code.google.com by [email protected] on 11 Jul 2012 at 4:15

QDecDouble::MaxStrSize too small

256 bytes is not enough to represent a double number of DBL_MAX or DBL_MIN

try this,

int main(int argc, char *argv[])
{    
    double d = DBL_MAX;
    QDecDouble dd(d);
}

and see the application happily crash.


Original issue reported on code.google.com by [email protected] on 17 Jan 2012 at 2:24

"1 + QDecDouble" causes an odd result without warnings

> What steps will reproduce the problem?

I compiled
      QDecDouble num("0.1");
      QDecDouble aux = 1 + num;
      cout << aux << endl;
and the result was
        8.19999E-393
which is very close to zero, which is not adequate. 

However, I compiled 
        double num(0.1);
        double aux = 1 + num;
        cout << aux << endl;
and the result was 
        1.1
which is correct. I obtained the same result using "qreal" instead of "double", 
of course.

> What version of the product are you using? On what operating system?
QDecimal 1.0.1. Kubuntu 13.04.

Thanks for QDecimal! 

Original issue reported on code.google.com by [email protected] on 10 Aug 2013 at 5:48

QDecNumber::toDouble() rounding defect


Reported by Aleksey Sukhonosov:

Please, take a look at the code:

    QDecNumber i;
    i.fromString("1.125");
    qDebug()<<i.toString()<<"~"<<QString::number(i.toDouble(),'f',2)<<" or "<<QString::number(QString("1.125").toDouble(),'f',2)<<" or "<<QString::number(QString(i.toString()).toDouble(),'f',2);
    i.fromString("1.375");
    qDebug()<<i.toString()<<"~"<<QString::number(i.toDouble(),'f',2)<<" or "<<QString::number(QString("1.375").toDouble(),'f',2)<<" or "<<QString::number(QString(i.toString()).toDouble(),'f',2);

The output should contain an original number and this number having been 
rounded. Every rounding method is supposed to give the same result. But in 
debug I have:

"1.125" ~ "1.00"  or  "1.12"  or  "1.12" 
"1.375" ~ "1.00"  or  "1.38"  or  "1.38" 

So, it seems that QDecNumber::toDouble() works in a wrong way, as everything it 
returns is of integer value (though, of double type).

Original issue reported on code.google.com by [email protected] on 29 Jan 2012 at 12:29

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.