4-3 FLOATING-POINT NUMBERS - SOME PRACTICAL ISSUES
***************************************************
The previous chapters discussed briefly the way floating-point
arithmetic is implemented in practice, In the following chapters
we will explore the consequences.
Topics discussed in this chapter:
Roundoff errors in practice
Little and Big-Endian machines
Porting binary files
Roundoff errors in practice
---------------------------
We have already said that roundoff errors are the result of the 'forced'
representation of the continuum of real numbers by a discrete subset.
Roundoff errors are generated when the internal representation is created,
and after almost every arithmetical operation performed, they accumulate
and are very difficult to estimate directly.
You can find if roundoff errors are trashing your computation in
the following ways:
1) Recomputing with a larger and more exact float type, e.g.
replace every REAL*4 in the program with REAL*8 or REAL*16,
recompute and compare the new results with the former.
If there is no significant difference you probably don't have
a roundoff problem.
2) Using a special compiler option, that truncates floating-point
results after a specified number of bits, with different values.
Such compiler option exists for CRAY's single precision floats
on CRAY computers (f77 -Wf-t n where n is in [0,47]).
3) Repeat the computation several times, each time randomly modify
(but in a controlled way) the value of some key variable.
See the example program in the chapter on numerical stability.
The idea is to add/subtract a small random number from the
variable under test. Controlled randomization can be applied
to different parts of the program, and the results of the
program can be examined, if they change unexpectedly, then
probably a numerical problem does exist.
The responsible piece of code can be located by applying the
randomization to different places, and watching the results.
4) Using an interval/stochastic arithmetic package. These methods
compute with each arithmetical operation the maximal error
(or an interval the true result must be within), or the most
probable error.
Using such arithmetical packages slows down the computation,
but may be very valuable during the development stage.
These extended arithmetics are implemented as procedure calls,
with a special preprocessor or with the function overloading
feature of Fortran 90.
5) Using a special compiler option that changes the rounding mode,
e.g. instead of rounding towards zero, round towards -infinity.
You can make roundoff errors smaller if you use a very large type of
floating-point numbers, DEC and Sun supports a non-standard REAL*16.
REAL*16 computations takes more CPU time than REAL*8 (X 3-13), but the
roundoff error is quite small compared with REAL*8.
See the chapter on performance measurements for an example program
that compares CPU time usage of different float types.
See the chapter on avoiding floating-point errors for other methods
to minimize roundoff errors.
However, don't think you can solve all numerical problems that way,
accuracy depends also on other factors except the size of the individual
roundoff errors. For example, unstable algorithms can trash even REAL*16
computations because they accumulate and magnify the individual roundoff
errors (see the chapter on stability).
Little and Big-Endian machines
------------------------------
Another practical complication arises when you store any multi-byte
entity in memory.
Computer memory is referenced by addresses that are positive integers.
It is 'natural' to store numbers with the LEAST SIGNIFICANT BYTE coming
before the MOST SIGNIFICANT BYTE in the computer memory, however
computer designers prefer sometimes to use a reversed order version of
the representation.
The 'natural' order, where less significant binary digits comes before
more significant digits in memory is called LITTLE-ENDIAN, many vendors
like IBM, CRAY and Sun preferred the reverse order that of course is
called BIG-ENDIAN.
Vendors and float types
-----------------------
Machine Endian Type Conversion
====== ====== ==== ==========
ALPHA LITTLE DEC/IEEE Several mechanisms
CRAY BIG ---- ---
HP ------ ---- ---
IBM BIG IBM ---
MAC BIG IEEE ---
PC LITTLE IEEE ---
SGI BIG IEEE ---
SUN BIG IEEE yes
VAX LITTLE DEC Several mechanisms
A small example program can check the endian status of your computer,
(of course the program would be less horrible if we used the BYTE
non-standard data type and EQUIVALENCE):
PROGRAM CHKEND
C ------------------------------------------------------------------
INTEGER*4
* I,
* ASCII_0, ASCII_1, ASCII_2, ASCII_3
C ------------------------------------------------------------------
PARAMETER(
* ASCII_0 = 48,
* ASCII_1 = 49,
* ASCII_2 = 50,
* ASCII_3 = 51)
C ------------------------------------------------------------------
COMMON // I
C ------------------------------------------------------------------
I = ASCII_0 + ASCII_1*256 + ASCII_2*(256**2) + ASCII_3*(256**3)
CALL SUB()
C ------------------------------------------------------------------
END
SUBROUTINE SUB()
C ------------------------------------------------------------------
CHARACTER
* I*4
C ------------------------------------------------------------------
COMMON // I
C ------------------------------------------------------------------
WRITE(*,*) ' Integer structure: ', I
WRITE(*,*) ' Byte order: ', '0123'
WRITE(*,*)
C ------------------------------------------------------------------
IF (I .EQ. '0123') THEN
WRITE(*,*) ' Machine is Little-Endian '
RETURN
ENDIF
C ------------------------------------------------------------------
IF (I .EQ. '3210') THEN
WRITE(*,*) ' Machine is Big-Endian '
RETURN
ENDIF
C ------------------------------------------------------------------
WRITE(*,*) ' Mixed endianity machine ... '
C ------------------------------------------------------------------
RETURN
END
The example program may have to be modified on 64 bit machines where
INTEGERs may be 8 bytes long.
Porting binary files
--------------------
See the chapter on files and records for a description of the
internal structure of unformatted files on different systems.
When you transfer binary (unformatted) files from one machine to
another that has different type of internal representation you
will need to perform some conversion. You will need to convert
between different floating point representations, different
endianity types, and there may also be differences in the file
formats used.
The most simple solution is to avoid transferring binary files and
use instead ASCII (formatted) files, the price is making the
transferred files about 2-3 times larger.
DEC and other vendors supplies some conversion mechanisms between
their NATIVE formats and the formats of others.
+---------------------------------------------------------------------+
| SUMMARY |
| ======= |
| 1) Roundoff errors accumulates; Can be crudely estimated |
| 2) Another complication, little/big endian representations |
| 3) Porting binary files may be a problem |
+---------------------------------------------------------------------+
A much more important factor in the social movement than those already mentioned was the ever-increasing influence of women. This probably stood at the lowest point to which it has ever fallen, during the classic age of Greek life and thought. In the history of Thucydides, so far as it forms a connected series of events, four times only during a period of nearly seventy years does a woman cross the scene. In each instance her apparition only lasts for a moment. In three of the four instances she is a queen or a princess, and belongs either to the half-barbarous kingdoms of northern Hellas or to wholly barbarous Thrace. In the one remaining instance208— that of the woman who helps some of the trapped Thebans to make their escape from Plataea—while her deed of mercy will live for ever, her name is for ever lost.319 But no sooner did philosophy abandon physics for ethics and religion than the importance of those subjects to women was perceived, first by Socrates, and after him by Xenophon and Plato. Women are said to have attended Plato’s lectures disguised as men. Women formed part of the circle which gathered round Epicurus in his suburban retreat. Others aspired not only to learn but to teach. Arêtê, the daughter of Aristippus, handed on the Cyrenaic doctrine to her son, the younger Aristippus. Hipparchia, the wife of Crates the Cynic, earned a place among the representatives of his school. But all these were exceptions; some of them belonged to the class of Hetaerae; and philosophy, although it might address itself to them, remained unaffected by their influence. The case was widely different in Rome, where women were far more highly honoured than in Greece;320 and even if the prominent part assigned to them in the legendary history of the city be a proof, among others, of its untrustworthiness, still that such stories should be thought worth inventing and preserving is an indirect proof of the extent to which feminine influence prevailed. With the loss of political liberty, their importance, as always happens at such a conjuncture, was considerably increased. Under a personal government there is far more scope for intrigue than where law is king; and as intriguers women are at least the209 equals of men. Moreover, they profited fully by the levelling tendencies of the age. One great service of the imperial jurisconsults was to remove some of the disabilities under which women formerly suffered. According to the old law, they were placed under male guardianship through their whole life, but this restraint was first reduced to a legal fiction by compelling the guardian to do what they wished, and at last it was entirely abolished. Their powers both of inheritance and bequest were extended; they frequently possessed immense wealth; and their wealth was sometimes expended for purposes of public munificence. Their social freedom seems to have been unlimited, and they formed combinations among themselves which probably served to increase their general influence.321 The old religions of Greece and Italy were essentially oracular. While inculcating the existence of supernatural beings, and prescribing the modes according to which such beings were to be worshipped, they paid most attention to the interpretation of the signs by which either future events in general, or the consequences of particular actions, were supposed to be divinely revealed. Of these intimations, some were given to the whole world, so that he who ran might read, others were reserved for certain favoured localities, and only communicated through the appointed ministers of the god. The Delphic oracle in particular enjoyed an enormous reputation both among Greeks and barbarians for guidance afforded under the latter conditions; and during a considerable period it may even be said to have directed the course of Hellenic civilisation. It was also under this form that supernatural religion suffered most injury from the great intellectual movement which followed the Persian wars. Men who had learned to study the constant sequences of Nature for themselves, and to shape their conduct according to fixed principles of prudence or of justice, either thought it irreverent to trouble the god about questions on which they were competent to form an opinion for themselves, or did not choose to place a well-considered scheme at the mercy of his possibly interested responses. That such a revolution occurred about the middle of the fifth century B.C., seems proved by the great change of tone in reference to this subject which one perceives on passing from Aeschylus to Sophocles. That anyone should question the veracity of an oracle is a supposition which never crosses the mind of the elder dramatist. A knowledge of augury counts among the greatest benefits222 conferred by Prometheus on mankind, and the Titan brings Zeus himself to terms by his acquaintance with the secrets of destiny. Sophocles, on the other hand, evidently has to deal with a sceptical generation, despising prophecies and needing to be warned of the fearful consequences brought about by neglecting their injunctions. The stranger had a pleasant, round face, with eyes that twinkled in spite of the creases around them that showed worry. No wonder he was worried, Sandy thought: having deserted the craft they had foiled in its attempt to get the gems, the man had returned from some short foray to discover his craft replaced by another. “Thanks,” Dick retorted, without smiling. When they reached him, in the dying glow of the flashlight Dick trained on a body lying in a heap, they identified the man who had been warned by his gypsy fortune teller to “look out for a hidden enemy.” He was lying at full length in the mould and leaves. "But that is sport," she answered carelessly. On the retirement of Townshend, Walpole reigned supreme and without a rival in the Cabinet. Henry Pelham was made Secretary at War; Compton Earl of Wilmington Privy Seal. He left foreign affairs chiefly to Stanhope, now Lord Harrington, and to the Duke of Newcastle, impressing on them by all means to avoid quarrels with foreign Powers, and maintain the blessings of peace. With all the faults of Walpole, this was the praise of his political system, which system, on the meeting of Parliament in the spring of 1731, was violently attacked by Wyndham and Pulteney, on the plea that we were making ruinous treaties, and sacrificing British interests, in order to benefit Hanover, the eternal millstone round the neck of England. Pulteney and Bolingbroke carried the same attack into the pages of The Craftsman, but they failed to move Walpole, or to shake his power. The English Government, instead of treating Wilkes with a dignified indifference, was weak enough to show how deeply it was touched by him, dismissed him from his commission of Colonel of the Buckinghamshire Militia, and treated Lord Temple as an abettor of his, by depriving him of the Lord-Lieutenancy of the same county, and striking his name from the list of Privy Councillors, giving the Lord-Lieutenancy to Dashwood, now Lord Le Despencer. "I tell you what I'll do," said the Deacon, after a little consideration. "I feel as if both Si and you kin stand a little more'n you had yesterday. I'll cook two to-day. We'll send a big cupful over to Capt. McGillicuddy. That'll leave us two for to-morrer. After that we'll have to trust to Providence." "Indeed you won't," said the Surgeon decisively. "You'll go straight home, and stay there until you are well. You won't be fit for duty for at least a month yet, if then. If you went out into camp now you would have a relapse, and be dead inside of a week. The country between here and Chattanooga is dotted with the graves of men who have been sent back to the front too soon." "Adone do wud that—though you sound more as if you wur in a black temper wud me than as if you pitied me." "Wot about this gal he's married?" "Don't come any further." "Davy, it 'ud be cruel of us to go and leave him." "Insolent priest!" interrupted De Boteler, "do you dare to justify what you have done? Now, by my faith, if you had with proper humility acknowledged your fault and sued for pardon—pardon you should have had. But now, you leave this castle instantly. I will teach you that De Boteler will yet be master of his own house, and his own vassals. And here I swear (and the baron of Sudley uttered an imprecation) that, for your meddling knavery, no priest or monk shall ever again abide here. If the varlets want to shrieve, they can go to the Abbey; and if they want to hear mass, a priest can come from Winchcombe. But never shall another of your meddling fraternity abide at Sudley while Roland de Boteler is its lord." "My lord," said Edith, in her defence, "this woman has sworn falsely. The medicine I gave was a sovereign remedy, if given as I ordered. Ten drops would have saved the child's life; but the contents of the phial destroyed it. The words I uttered were prayers for the life of the child. My children, and all who know me, can bear witness that I have a custom of asking His blessing upon all I take in hand. I raised my eyes towards heaven, and muttered words; but, my lord, they were words of prayer—and I looked up as I prayed, to the footstool of the Lord. But it is in vain to contend: the malice of the wicked will triumph, and Edith Holgrave, who even in thought never harmed one of God's creatures, must be sacrificed to cover the guilt, or hide the thoughtlessness of another." "Aye, Sir Treasurer, thou hast reason to sink thy head! Thy odious poll-tax has mingled vengeance—nay, blood—with the cry of the bond." HoME古一级毛片免费观看
ENTER NUMBET 0017 www.paici4.net.cn www.danji4.net.cn www.kmdt.com.cn www.banri5.com.cn www.lite6.net.cn www.hebei7.net.cn www.xiaer7.net.cn www.zhuya5.com.cn www.hkhbcc.com.cn www.91cyhd.com.cn