High Precision computing (1) -- Introduction

Source: Internet
Author: User

We know that at present, the computer computing value has a high accuracy, but due to hardware restrictions, it is often unable to meet the actual production needs, so we can achieve high-precision computing through careful design of the program. Let's talk about this issue today.

First, we should know that,Working principle of high-precision computing:

Like a vertical bar, we can use the vertical carry and borrow bits to store data and perform operations and calculations of string functions to achieve high-precision computing.

Eg.

5 2 2 A3 A2 A1

+ 6 2 3 + B3 B2 B1

____________________ ====> _________________________

1 1 4 5 C4 C3 C2 C1

So what should we pay attention to in high-precision computing?

This is a long story ······

1. Data Receiving and storage

When the input data is very long... BITs), we only need to open enough string length, the operation and calculation of the string function, each bit is taken out, stored in the array.

1 void Init (int A []) {/* input array */2 3 string s; 4 5 CIN> S; 6 7 A [0] = S. length ();/* use a [0] to calculate the number of digits of string S */8 9 for (I = 1; I <= A [0]; I ++) 10 A [I] = s [A [0]-I]-'0'; 11/* s -----> A [], in reverse order */12 13}

Another method is to directly add arrays through loops.

2. determine the number of high-precision digits

Determine the number of digits: the string is often used for receiving, so the number of digits = the length of the string.

 

3. Carry and return

 

1/* addition carry */2 C [I] = A [I] + B [I]; 3 if (C [I]> = 10) {4 5 C [I] % = 10; 6 ++ C [I + 1]; 7 8} 9 10/* subtraction carry */11 if (a [I] <B [I]) {12 13 -- A [I]; 14 A [I] + = 10; 15 16} 17 18 C [I] = A [I]-B [I]; 19 20/* multiplication carry */21 C [I + J-1] = A [I] * B [J] + x + C [I + I-1]; 22 x = C [I + J-1]/10; 23 C [I + J-1] % = 10;

 

The above is the theoretical knowledge of high-precision computing. I will issue relevant examples in the future.

Thank you!

 

High Precision computing (1) -- Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.