bcd.hpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*##############################################################################
  2. Copyright (C) 2011 HPCC Systems.
  3. All rights reserved. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ############################################################################## */
  14. #ifndef _BCD_
  15. #define _BCD_
  16. #include "platform.h"
  17. #ifdef _WIN32
  18. #ifdef NBCD_EXPORTS
  19. #define nbcd_decl __declspec(dllexport)
  20. #else
  21. #define nbcd_decl __declspec(dllimport)
  22. #endif
  23. #else
  24. #define nbcd_decl
  25. #endif
  26. #ifndef _WIN32
  27. #define _fastcall
  28. #define __fastcall
  29. #endif
  30. nbcd_decl void _fastcall DecAbs( void ); // make top of stack absolute
  31. nbcd_decl void _fastcall DecAdd( void ); // add top two values on stack and replace with result
  32. nbcd_decl int _fastcall DecCompareNull( void ); // compare top of stack to NULL, returns result, takes value of stack
  33. nbcd_decl int _fastcall DecDistinct( void ); // compares second to top value on stack, removes them and returns result
  34. nbcd_decl int _fastcall DecDistinctR( void ); // compares top to second value on stack, removes them and returns result
  35. nbcd_decl void _fastcall DecDivide( void ); // divide second by top value on stack and replace with result
  36. nbcd_decl void _fastcall DecDivideR( void ); // divide top by second value on stack and replace with result
  37. nbcd_decl void _fastcall DecDup( void ); // duplicate value on top of decimal stack
  38. nbcd_decl void _fastcall DecSetPrecision(unsigned char declen, unsigned char prec); // changes length and precision of top value on stack
  39. nbcd_decl void _fastcall DecSub( void ); // substract top from second value on stack and replace with result
  40. nbcd_decl void _fastcall DecSubR( void ); // substract second from top value on stack and replace with result
  41. nbcd_decl void _fastcall DecInfo(unsigned & digits, unsigned & prec); // returns the digits and precision of top value on stack
  42. nbcd_decl void _fastcall DecClipInfo(unsigned & digits, unsigned & prec);
  43. nbcd_decl void _fastcall DecLongPower(long pow); // calculates top of stack to the power of long and replaces with result
  44. nbcd_decl void _fastcall DecModulus( void ); // modulus second by top value on stack and replace with result
  45. nbcd_decl void _fastcall DecMul( void ); // multiply values top and second on the stack and replace with result
  46. nbcd_decl void _fastcall DecNegate( void ); // negate value on top of the decimal stack
  47. nbcd_decl void _fastcall DecPopCString (unsigned, char *); // Pops decimal accumulator into CString
  48. nbcd_decl char * _fastcall DecPopCStringX(); // Pop decimal accumulator into CString allocated on heap
  49. nbcd_decl __int64 _fastcall DecPopInt64( void ); // Pops decimal accumulator into __Int64
  50. nbcd_decl void _fastcall DecPopDecimal(void * tgt,unsigned char declen,unsigned char prec); // Pops decimal value of the stack
  51. nbcd_decl void _fastcall DecPopUDecimal(void * tgt,unsigned char declen,unsigned char prec); // Pops unsigned decimal value of the stack
  52. nbcd_decl int _fastcall DecPopLong( void ); // Pops decimal accumulator into long
  53. nbcd_decl unsigned long _fastcall DecPopUlong( void ); // Pops decimal accumulator into unsigned long
  54. nbcd_decl double _fastcall DecPopReal( void ); // Pops decimal accumulator into real (double)
  55. nbcd_decl unsigned _fastcall DecPopString( unsigned, char * ); // Pops decimal accumulator into string
  56. nbcd_decl void _fastcall DecPopStringX( unsigned &, char * & ); // Pops decimal accumulator into string, determines size and allocates string
  57. nbcd_decl void _fastcall DecPushCString(const char *s); // Pushes CString onto decimal stack
  58. nbcd_decl void _fastcall DecPushInt64(__int64 ); // Pushes __Int64 onto decimal stack
  59. nbcd_decl void _fastcall DecPushUInt64(unsigned __int64 ); // Pushes unsigned __Int64 onto decimal stack
  60. nbcd_decl void _fastcall DecPushLong( long ); // Pushes long value onto decimal stack
  61. nbcd_decl void _fastcall DecPushDecimal(const void *,unsigned char declen,unsigned char prec); // Pushes decimal value onto the stack
  62. nbcd_decl void _fastcall DecPushUDecimal(const void *,unsigned char declen,unsigned char prec); // Pushes unsigned decimal value onto the stack
  63. nbcd_decl void _fastcall DecPushReal( double d ); // pushes real (double) onto decimal stack
  64. nbcd_decl void _fastcall DecPushString(unsigned, const char * ); // Pushes string onto decimal stack
  65. nbcd_decl void _fastcall DecPushUlong( unsigned long ); // Pushes unsigned long value onto decimal stack
  66. nbcd_decl void _fastcall DecRestoreStack( void * ); // Restore decimal stack
  67. nbcd_decl void _fastcall DecRound( void ); // round value on top of decimal stack
  68. nbcd_decl void _fastcall DecRoundUp( void ); // round value on top of decimal stack
  69. nbcd_decl void _fastcall DecRoundTo( unsigned places ); // round value on top of decimal stack
  70. nbcd_decl void * _fastcall DecSaveStack( void ); // Save decimal stack
  71. nbcd_decl void _fastcall DecSwap( void ); // swap top and second values on decimal stack
  72. nbcd_decl void _fastcall DecTruncate( void ); // truncate value on top of decimal stack
  73. nbcd_decl void _fastcall DecTruncateAt(unsigned places); // truncate value on top of decimal stack
  74. nbcd_decl void _fastcall DecUlongPower(unsigned long pow); // calculates top of stack to the power of unsigned long and replaces with result
  75. nbcd_decl void _fastcall DecLock();
  76. nbcd_decl void _fastcall DecUnlock();
  77. nbcd_decl bool _fastcall DecValid(bool isSigned, unsigned digits, const void * data);
  78. nbcd_decl bool _fastcall Dec2Bool(size32_t bytes, const void * data);
  79. nbcd_decl bool _fastcall UDec2Bool(size32_t bytes, const void * data);
  80. nbcd_decl int _fastcall DecCompareDecimal(size32_t bytes, const void * _left, const void * _right);
  81. nbcd_decl int _fastcall DecCompareUDecimal(size32_t bytes, const void * _left, const void * _right);
  82. // internal
  83. void AddBytes(unsigned dest,unsigned src,unsigned num);
  84. nbcd_decl char _fastcall DecClip(void *);
  85. nbcd_decl void _fastcall DecRoundPos(void *,int by);
  86. nbcd_decl void _fastcall SetMAccum(unsigned char c);
  87. struct nbcd_decl BcdCriticalBlock
  88. {
  89. inline BcdCriticalBlock() { DecLock(); }
  90. inline ~BcdCriticalBlock() { DecUnlock(); }
  91. };
  92. #endif