Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A brief Analysis of "big data Operation"-addition, subtraction, multiplication and Division and Modular Division

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

WAY?

Why Big Data Computing? Reason?

The commonly used data types in c++ are char:1 bit,short 2 bit, int 4 bit, long 8 bit, etc. The data size identified by the above data types is very limited. If it is larger than the range they can represent, the calculation result will be wrong. The same is true for calculators in daily life. The calculation of two relatively large numbers in our country will also cause errors, or it cannot be displayed normally.

For example, calculate 123456789123456789*987654321987654321

The calculation results are as follows:

The differences are as follows:

Analysis:

There are two kinds of situations in data operation: one is data, and small calculation results will not overflow; the other is data overflow or calculation results will overflow;

Therefore, in order to make the calculation convenient and save the amount of calculation, I have set up the following two ways to store data, and in the calculation, different methods are selected according to different situations, as follows:

Did what?

In order to solve the above problems, I wrote a small project to calculate the four operations of big data and modulo, and the functions realized are + - * / %;

The main interfaces and implementation code are as follows:

The program header file and interfaces are as follows:

/** * Project Name: Big Data Operation * Interface Name: BigData.h * by: Zou Ming * Completion time: 2016.04.12**/#ifndef __BIG_DATA_H__#define __BIG_DATA_H__#including using namespace std;#include#define MAX_INT64 0x7 FFFF//Maximum value that small data can represent #define MIN_INT64 0x80000000000 //the smallest value that a small data can represent #define INIT 0xcctypedef long INT64;class BigData{public: BigData(INT64 value= INIT); BigData(const char*ptrData); //operator overloading BigData operator+(const BigData& bigdata); BigData operator-(const BigData& bigdata); BigData operator*(const BigData& bigdata); BigData operator/(const BigData& bigdata); BigData operator%(const BigData& bigdata);private: std::string Add(std::string left, std::string right); std::string Sub(std::string left, std::string right); std::string Mul(std::string left, std::string right); std::string Div(std::string left, std::string right); std::string Mod(std::string left, std::string right); //modulo bool IsINT64OverFlow() const; //Determine whether the flow is out of bounds void INT64ToString(); //convert data to string bool IsLeftStrBig(const char *pLeft, int LSise, const char *pRight, int RSise); //compare left operand is greater than all operands char SubLoop(char *pLeft, int LSise, const char *pRight, int RSise); //Each quotient operation in division friend std::ostream&operator= 0))) { return true; } return false;}//output operator overloading std::ostream&operator

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report