diff options
author | Damjan Jovanovic <damjan@apache.org> | 2015-12-06 18:17:33 +0000 |
---|---|---|
committer | Damjan Jovanovic <damjan@apache.org> | 2015-12-06 18:17:33 +0000 |
commit | 6fc5d5e8812de2983973198dabbb6ae911f9fabe (patch) | |
tree | da3ab7a438a0b2e72633963b84b6926c7b810c52 /sc | |
parent | efd7dfd2e39dbe4cb894156b3cc2c11c44ae845e (diff) |
#i126701# Patch for adding bit shift functions to calc
Patch by: Pathangi Janardhanan Jatinshravan <JATINSHR001 at e dot ntu dot edu dot sg>
Review by: me
Notes
Notes:
prefer: c6b49f9098fb6c9816202e8d465c342788736af5
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/helpids.h | 2 | ||||
-rw-r--r-- | sc/source/core/inc/interpre.hxx | 9 | ||||
-rw-r--r-- | sc/source/core/tool/interpr1.cxx | 42 | ||||
-rw-r--r-- | sc/source/core/tool/interpr4.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/src/scfuncs.src | 64 | ||||
-rw-r--r-- | sc/util/hidother.src | 2 |
6 files changed, 121 insertions, 0 deletions
diff --git a/sc/inc/helpids.h b/sc/inc/helpids.h index ae09a53a04dd..f3554333faad 100644 --- a/sc/inc/helpids.h +++ b/sc/inc/helpids.h @@ -777,3 +777,5 @@ #define HID_FUNC_BITAND "SC_HID_FUNC_BITAND" #define HID_FUNC_BITOR "SC_HID_FUNC_BITOR" #define HID_FUNC_BITXOR "SC_HID_FUNC_BITXOR" +#define HID_FUNC_BITLSHIFT "SC_HID_FUNC_BITLSHIFT" +#define HID_FUNC_BITRSHIFT "SC_HID_FUNC_BITRSHIFT"
\ No newline at end of file diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx index 2e1aedef888c..36a2c3be5587 100644 --- a/sc/source/core/inc/interpre.hxx +++ b/sc/source/core/inc/interpre.hxx @@ -149,6 +149,12 @@ public: BITOR, BITXOR }; + + enum bitShift + { + BITLSHIFT, + BITRSHIFT + }; }; DECL_FIXEDMEMPOOL_NEWDEL( ScInterpreter ) @@ -526,6 +532,9 @@ void ScBitAnd(); void ScBitOr(); void ScBitXor(); void ScBitArithmeticOps( bitOperations::bitArithmetic ); +void ScBitLShift(); +void ScBitRShift(); +void ScBitShiftOps(bitOperations::bitShift); // If upon call rMissingField==sal_True then the database field parameter may be // missing (Xcl DCOUNT() syntax), or may be faked as missing by having the diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index 864cb860bc34..4cfb9639e560 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -1207,6 +1207,48 @@ void ScInterpreter::ScBitArithmeticOps(bitOperations::bitArithmetic bitOp) } } +void ScInterpreter::ScBitRShift() { + ScBitShiftOps(bitOperations::BITRSHIFT); +} + +void ScInterpreter::ScBitLShift() { + ScBitShiftOps(bitOperations::BITLSHIFT); +} + +void ScInterpreter::ScBitShiftOps(bitOperations::bitShift bitOp) { + if ( MustHaveParamCount( GetByte(), 2 ) ) + { + double n = ::rtl::math::approxFloor( GetDouble() ); + double val = ::rtl::math::approxFloor( GetDouble() ); + + if ( val < 0 ) + { + PushIllegalArgument(); + } + else + { + double result; + if (n < 0) + { + if (bitOp == bitOperations::BITLSHIFT) + result = (sal_uInt64) val >> (sal_uInt64) -n; + else + result = (sal_uInt64) val << (sal_uInt64) -n; + } + else if( n == 0) + result = val; + else + { + if (bitOp == bitOperations::BITLSHIFT) + result = (sal_uInt64) val << (sal_uInt64) n; + else + result = (sal_uInt64) val >> (sal_uInt64) n; + + } + PushDouble( result ); + } + } +} void ScInterpreter::ScAnd() { diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx index 2232717e5703..83161bfed07c 100644 --- a/sc/source/core/tool/interpr4.cxx +++ b/sc/source/core/tool/interpr4.cxx @@ -3769,6 +3769,8 @@ StackVar ScInterpreter::Interpret() case ocBitAnd : ScBitAnd(); break; case ocBitOr : ScBitOr(); break; case ocBitXor : ScBitXor(); break; + case ocBitLShift : ScBitLShift(); break; + case ocBitRShift : ScBitRShift(); break; case ocNone : nFuncFmtType = NUMBERFORMAT_UNDEFINED; break; default : PushError( errUnknownOpCode); break; } diff --git a/sc/source/ui/src/scfuncs.src b/sc/source/ui/src/scfuncs.src index 81274c7cd57a..d00fa9be1569 100644 --- a/sc/source/ui/src/scfuncs.src +++ b/sc/source/ui/src/scfuncs.src @@ -9533,6 +9533,70 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS2 }; }; + Resource SC_OPCODE_BITLSHIFT + { + String 1 // Description + { + Text [ en-US ] = "Bitwise left shift of an integer value."; + }; + ExtraData = + { + 0; + ID_FUNCTION_GRP_MATH; + U2S( HID_FUNC_BITLSHIFT ); + 2; 0; 0; + 0; + }; + String 2 // Name of Parameter 1 + { + Text [ en-US ] = "Number" ; + }; + String 3 // Description of Parameter 1 + { + Text [ en-US ] = "The value to be shifted. Positive integer." ; + }; + String 4 // Name of Parameter 2 + { + Text [ en-US ] = "Shift" ; + }; + String 5 // Description of Parameter 2 + { + Text [ en-US ] = "The number of bits the first argument is to be shifted by." ; + }; + }; + + Resource SC_OPCODE_BITRSHIFT + { + String 1 // Description + { + Text [ en-US ] = "Bitwise right shift of an integer value."; + }; + ExtraData = + { + 0; + ID_FUNCTION_GRP_MATH; + U2S( HID_FUNC_BITRSHIFT ); + 2; 0; 0; + 0; + }; + String 2 // Name of Parameter 1 + { + Text [ en-US ] = "Number" ; + }; + String 3 // Description of Parameter 1 + { + Text [ en-US ] = "The value to be shifted. Positive integer." ; + }; + String 4 // Name of Parameter 2 + { + Text [ en-US ] = "Shift" ; + }; + String 5 // Description of Parameter 2 + { + Text [ en-US ] = "The number of bits the first argument is to be shifted by." ; + }; + }; + }; #if defined(U2S) diff --git a/sc/util/hidother.src b/sc/util/hidother.src index b3dc678420f4..c1a5818cdbcf 100644 --- a/sc/util/hidother.src +++ b/sc/util/hidother.src @@ -489,3 +489,5 @@ hidspecial HID_DAI_FUNC_ROT13 { HelpID = HID_DAI_FUNC_ROT13; }; hidspecial HID_FUNC_BITAND { HelpID = HID_FUNC_BITAND; }; hidspecial HID_FUNC_BITOR { HelpID = HID_FUNC_BITOR; }; hidspecial HID_FUNC_BITXOR { HelpID = HID_FUNC_BITXOR; }; +hidspecial HID_FUNC_BITLSHIFT { HelpID = HID_FUNC_BITLSHIFT; }; +hidspecial HID_FUNC_BITRSHIFT { HelpID = HID_FUNC_BITRSHIFT; }; |