rtlbcd.hpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef _RTLBCD_HPP_
  14. #define _RTLBCD_HPP_
  15. #include "eclrtl.hpp"
  16. ECLRTL_API void DecAbs( void ); // make top of stack absolute
  17. ECLRTL_API void DecAdd( void ); // add top two values on stack and replace with result
  18. ECLRTL_API int DecCompareNull( void ); // compare top of stack to NULL, returns result, takes value of stack
  19. ECLRTL_API int DecDistinct( void ); // compares second to top value on stack, removes them and returns result
  20. ECLRTL_API int DecDistinctR( void ); // compares top to second value on stack, removes them and returns result
  21. ECLRTL_API void DecDivide(byte dbz); // divide second by top value on stack and replace with result
  22. ECLRTL_API void DecDivideR(byte dbz); // divide top by second value on stack and replace with result
  23. ECLRTL_API void DecDup( void ); // duplicate value on top of decimal stack
  24. ECLRTL_API void DecSetPrecision(unsigned char declen, unsigned char prec); // changes length and precision of top value on stack
  25. ECLRTL_API void DecSub( void ); // substract top from second value on stack and replace with result
  26. ECLRTL_API void DecSubR( void ); // substract second from top value on stack and replace with result
  27. ECLRTL_API void DecInfo(unsigned & digits, unsigned & prec); // returns the digits and precision of top value on stack
  28. ECLRTL_API void DecClipInfo(unsigned & digits, unsigned & prec);
  29. ECLRTL_API void DecLongPower(long pow); // calculates top of stack to the power of long and replaces with result
  30. ECLRTL_API void DecModulus(byte dbz); // modulus second by top value on stack and replace with result
  31. ECLRTL_API void DecMul( void ); // multiply values top and second on the stack and replace with result
  32. ECLRTL_API void DecNegate( void ); // negate value on top of the decimal stack
  33. ECLRTL_API void DecPopCString (unsigned, char *); // Pops decimal accumulator into CString
  34. ECLRTL_API char * DecPopCStringX(); // Pop decimal accumulator into CString allocated on heap
  35. ECLRTL_API __int64 DecPopInt64( void ); // Pops decimal accumulator into __Int64
  36. ECLRTL_API void DecPopDecimal(void * tgt,unsigned char declen,unsigned char prec); // Pops decimal value of the stack
  37. ECLRTL_API void DecPopUDecimal(void * tgt,unsigned char declen,unsigned char prec); // Pops unsigned decimal value of the stack
  38. ECLRTL_API int DecPopLong( void ); // Pops decimal accumulator into long
  39. ECLRTL_API unsigned long DecPopUlong( void ); // Pops decimal accumulator into unsigned long
  40. ECLRTL_API double DecPopReal( void ); // Pops decimal accumulator into real (double)
  41. ECLRTL_API unsigned DecPopString( unsigned, char * ); // Pops decimal accumulator into string
  42. ECLRTL_API void DecPopStringX( unsigned &, char * & ); // Pops decimal accumulator into string, determines size and allocates string
  43. ECLRTL_API void DecPushCString(const char *s); // Pushes CString onto decimal stack
  44. ECLRTL_API void DecPushInt64(__int64 ); // Pushes __Int64 onto decimal stack
  45. ECLRTL_API void DecPushUInt64(unsigned __int64 ); // Pushes unsigned __Int64 onto decimal stack
  46. ECLRTL_API void DecPushLong( long ); // Pushes long value onto decimal stack
  47. ECLRTL_API void DecPushDecimal(const void *,unsigned char declen,unsigned char prec); // Pushes decimal value onto the stack
  48. ECLRTL_API void DecPushUDecimal(const void *,unsigned char declen,unsigned char prec); // Pushes unsigned decimal value onto the stack
  49. ECLRTL_API void DecPushReal( double d ); // pushes real (double) onto decimal stack
  50. ECLRTL_API void DecPushString(unsigned, const char * ); // Pushes string onto decimal stack
  51. ECLRTL_API void DecPushUlong( unsigned long ); // Pushes unsigned long value onto decimal stack
  52. ECLRTL_API void DecRestoreStack( void * ); // Restore decimal stack
  53. ECLRTL_API void DecRound( void ); // round value on top of decimal stack
  54. ECLRTL_API void DecRoundUp( void ); // round value on top of decimal stack
  55. ECLRTL_API void DecRoundTo( unsigned places ); // round value on top of decimal stack
  56. ECLRTL_API void * DecSaveStack( void ); // Save decimal stack
  57. ECLRTL_API void DecSwap( void ); // swap top and second values on decimal stack
  58. ECLRTL_API void DecTruncate( void ); // truncate value on top of decimal stack
  59. ECLRTL_API void DecTruncateAt(unsigned places); // truncate value on top of decimal stack
  60. ECLRTL_API void DecUlongPower(unsigned long pow); // calculates top of stack to the power of unsigned long and replaces with result
  61. ECLRTL_API bool DecValid(bool isSigned, unsigned digits, const void * data);
  62. ECLRTL_API bool DecValidTos();
  63. ECLRTL_API bool Dec2Bool(size32_t bytes, const void * data);
  64. ECLRTL_API bool UDec2Bool(size32_t bytes, const void * data);
  65. ECLRTL_API int DecCompareDecimal(size32_t bytes, const void * _left, const void * _right);
  66. ECLRTL_API int DecCompareUDecimal(size32_t bytes, const void * _left, const void * _right);
  67. // internal
  68. void AddBytes(unsigned dest,unsigned src,unsigned num);
  69. ECLRTL_API char DecClip(void *);
  70. ECLRTL_API void DecRoundPos(void *,int by);
  71. ECLRTL_API void SetMAccum(unsigned char c);
  72. ECLRTL_API void DecLock();
  73. ECLRTL_API void DecUnlock();
  74. ECLRTL_API unsigned DecMarkStack();
  75. ECLRTL_API void DecReleaseStack(unsigned mark);
  76. //No longer a critical section (since stack is thread_local), but prevents problems with exceptions.
  77. class ECLRTL_API BcdCriticalBlock
  78. {
  79. public:
  80. inline BcdCriticalBlock() { mark = DecMarkStack(); }
  81. inline ~BcdCriticalBlock() { DecReleaseStack(mark); }
  82. protected:
  83. unsigned mark;
  84. };
  85. #endif