Say, is it correct to often want the floating number operation result in the check routine during writer as the one-chip computer programmer, but there is no appropriate test tool in the hand, very troublesome. The general one-chip computer has no arithmetical instruction of floating number, must work out the corresponding software by oneself. While calculating division, the method to usually use is the comparative division, namely utilize cyclic shift and subtraction to be operated to get 24- 32 traders, efficiency is very low. Provide the operation practical fast algorithm of a kind of floating number division here. This method regards numerical calculation prediction – correcting method as guidance, has fully utilized 16 multiplication and division method functions of one-chip computer, have realized the division of the floating number very easily.

A floating number form

The floating number standard of IEEE has stipulated single precision ‘ 4 bytes , double precision 8 bytes And expand the precision ‘ 10 bytes The forms of three kinds of floating numbers. The most frequently used one is the floating number of the single precision, the form is shown as in Fig. 1. But this kind of form is not characteristic in the same byte unit, difficult addressing, thus will influence the operation speed.

It was the floating number of a kind of form out of shape that was usually adopted on the one-chip computer, as shown in Fig. 2. 23 mantissas among them add the implicit most significant position 1, form a fixed point true code decimal, the mantissa is smaller than 1 and greater than equalling by decimal of 0.5.

Algorithm principle of 2 fast division

There are only 16′s multiplication and division methods, and the precision namely the significiant figure of the mantissa of the floating number in 16 one-chip computers Up to 24, so can’t deduct directly, but can still make use of 16′s multiplication and division method order to realize 24 division. However, if only carry on 16′s division once and must be known and brought the error greatly, so how key to the question lies in dispels this error, thus reach claimed accuracy. This is actually usually prediction adopted – correcting method in numerical calculation.

Suppose two floating numbers after preconditioning, dividend and divisor mantissa are expanded to the 32-bit microcomputer 8 persons of the end are 0 Put into X and Y separately. The neighbor YL for low 16 of Y, and write YH =Y-YL. Obviously YH Y, X/Y similar to Y/YH looks:

It is obvious that only needs to multiply by another modifying factor YH-YL on the basis of X/YH /YH, can get a calibration value of X/Y. It is easy to prove this value has already met requirements for 24′s precision. In fact, the relative divergence is satisfied:

It means a calibration value can well be regarded as the final result.

It is realized specifically that 3 is algorithmic

While realizing an algorithm specifically, mainly pass the following steps:

Although YH here is still a 32-bit microcomputer, low 16 of its have already been 0, can regard it as 16 figures when calculating, this will not influence calculating precision. Through twice and 16 division, can receive the rigorous 32-bit microcomputer result. For example calculate Q0, first division, X divided by high 16 of YH, trader that get high 16 of Q0, and 16 the intersection of remainder and end add, 0 become 32-bit microcomputer, again divided by high 16 of YH, get low 16 of Q0 remainder is cast out . Therefore has got Q0 of the 32-bit microcomputer.

In concrete operation, should X select divided by 4 X move 2 to left ,In order to guarantee Q0 will not overflow YH fetches 16 high :

Because X is a 32-bit microcomputer ‘ 8 of the end are 0 ,This operation does not influence the significant digit. And The problem of overflowing does not exist. While calculating the calibration value Q finally, yes .

It calculate Q0 ‘, Q1 at,last 16 divisions,last Q0 ‘, Q1 is 32-bit microcomputers rigorous, have guaranteed the precision in the computational process, has reduced the accumulated error. As to YL =0 and 16 effective numberical special circumstances that there are the divisors only promptly, there is Q1 directly =1,Still can save 16 division twice.

Say, is it correct to often want the floating number operation result in the check routine during writer as the one-chip computer programmer, but there is no appropriate test tool in the hand, very troublesome. The general one-chip computer has no arithmetical instruction of floating number, must work out the corresponding software by oneself. While calculating division, the method to usually use is the comparative division, namely utilize cyclic shift and subtraction to be operated to get 24- 32 traders, efficiency is very low. Provide the operation practical fast algorithm of a kind of floating number division here. This method regards numerical calculation prediction – correcting method as guidance, has fully utilized 16 multiplication and division method functions of one-chip computer, have realized the division of the floating number very easily.

A floating number form

The floating number standard of IEEE has stipulated single precision ‘ 4 bytes , double precision 8 bytes And expand the precision ‘ 10 bytes The forms of three kinds of floating numbers. The most frequently used one is the floating number of the single precision, the form is shown as in Fig. 1. But this kind of form is not characteristic in the same byte unit, difficult addressing, thus will influence the operation speed.

It was the floating number of a kind of form out of shape that was usually adopted on the one-chip computer, as shown in Fig. 2. 23 mantissas among them add the implicit most significant position 1, form a fixed point true code decimal, the mantissa is smaller than 1 and greater than equalling by decimal of 0.5.

Algorithm principle of 2 fast division

There are only 16′s multiplication and division methods, and the precision namely the significiant figure of the mantissa of the floating number in 16 one-chip computers Up to 24, so can’t deduct directly, but can still make use of 16′s multiplication and division method order to realize 24 division. However, if only carry on 16′s division once and must be known and brought the error greatly, so how key to the question lies in dispels this error, thus reach claimed accuracy. This is actually usually prediction adopted – correcting method in numerical calculation.

Suppose two floating numbers after preconditioning, dividend and divisor mantissa are expanded to the 32-bit microcomputer 8 persons of the end are 0 Put into X and Y separately. The neighbor YL for low 16 of Y, and write YH =Y-YL. Obviously YH Y, X/Y similar to Y/YH looks:

It is obvious that only needs to multiply by another modifying factor YH-YL on the basis of X/YH /YH, can get a calibration value of X/Y. It is easy to prove this value has already met requirements for 24′s precision. In fact, the relative divergence is satisfied:

It means a calibration value can well be regarded as the final result.

It is realized specifically that 3 is algorithmic

While realizing an algorithm specifically, mainly pass the following steps:

Although YH here is still a 32-bit microcomputer, low 16 of its have already been 0, can regard it as 16 figures when calculating, this will not influence calculating precision. Through twice and 16 division, can receive the rigorous 32-bit microcomputer result. For example calculate Q0, first division, X divided by high 16 of YH, trader that get high 16 of Q0, and 16 the intersection of remainder and end add, 0 become 32-bit microcomputer, again divided by high 16 of YH, get low 16 of Q0 remainder is cast out . Therefore has got Q0 of the 32-bit microcomputer.

In concrete operation, should X select divided by 4 X move 2 to left ,In order to guarantee Q0 will not overflow YH fetches 16 high :

Because X is a 32-bit microcomputer ‘ 8 of the end are 0 ,This operation does not influence the significant digit. And ,The problem of overflowing does not exist. While calculating the calibration value Q finally, yes .

It calculate on Q0 ‘, Q1 at,last 16 divisions,last Q0 ‘, Q1 is 32-bit microcomputers rigorous, have guaranteed the precision in the computational process, has reduced the accumulated error. As to YL =0 and 16 effective numberical special circumstances that there are the divisors only promptly, there is Q1 directly =1,Still can save 16 division twice.

While calculating Q, realize the 32-bit microcomputer multiplication through 3 times and 16 multiplication, fetch the consequential high 32-bit microcomputer, get Q.

The whole algorithm need only use division 4 times, multiplication 3 times and 5 additions at most, can ask the mantissa in Shang of the floating number, it is obvious computational efficiency is very high, have guaranteed the operation speed.

The division flow block diagram of the floating number is shown as in Fig. 3.

4 procedure source codes

As space is limited, only provide the key part in the source code, namely effective numberical calculated part.

Code, up to here, floating number significant digit in trader all found. So long as carry out a little more operation of adjustment with characteristic floating number, can receive the net result.

In an 80C196KC one-chip computer system that the author developed, involve binary scale – decimal numbering system change, segment linear interpolation, numerical filtering a large number of operation of floating number, all realize by bottom layer functions such as the additioin, subtraction, multiplication and division,etc..

In addition, the thinking of this algorithm is clear, so is very easy to popularize. For example, in order to receive more high precision, desirable modifying factor:

Then relative divergence ,Turn into the decimal system, the significant digit is up to 14.