1、raising standards worldwide NO COPYING WITHOUT BSI PERMISSION EXCEPT AS PERMITTED BY COPYRIGHT LAW BSI Standards Publication BS ISO/IEC 10967-1:2012 Information technology Language independent arithmetic Part 1: Integer and floating point arithmeticBS ISO/IEC 10967-1:2012 BRITISH STANDARD National f
2、oreword This British Standard is the UK implementation of ISO/IEC 10967-1:2012. It supersedes BS ISO/IEC 10967-1:1994 which is withdrawn. The UK participation in its preparation was entrusted to Technical Committee IST/5, Programming languages, their environments and system software interfaces. A li
3、st of organizations represented on this committee can be obtained on request to its secretary. This publication does not purport to include all the necessary provisions of a contract. Users are responsible for its correct application. The British Standards Institution 2012. Published by BSI Standard
4、s Limited 2012 ISBN 978 0 580 63696 7 ICS 35.060 Compliance with a British Standard cannot confer immunity from legal obligations. This British Standard was published under the authority of the Standards Policy and Strategy Committee on 31 July 2012. Amendments issued since publication Date Text aff
5、ectedBS ISO/IEC 10967-1:2012Reference number ISO/IEC 10967-1:2012(E) ISO/IEC 2012INTERNATIONAL STANDARD ISO/IEC 10967-1 Second edition 2012-07-15 Information technology Language independent arithmetic Part 1: Integer and floating point arithmetic Technologies de linformation Arithmtique indpendante
6、de langage Partie 1: Arithmtique de nombres entiers et en virgule flottante BS ISO/IEC 10967-1:2012 ISO/IEC 10967-1:2012(E) COPYRIGHT PROTECTED DOCUMENT ISO/IEC 2012 All rights reserved. Unless otherwise specified, no part of this publication may be reproduced or utilized in any form or by any means
7、, electronic or mechanical, including photocopying and microfilm, without permission in writing from either ISO at the address below or ISOs member body in the country of the requester. ISO copyright office Case postale 56 CH-1211 Geneva 20 Tel. + 41 22 749 01 11 Fax + 41 22 749 09 47 E-mail copyrig
8、htiso.org Web www.iso.org Published in Switzerland ii ISO/IEC 2012 All rights reservedBS ISO/IEC 10967-1:2012 Contents Foreword vii Introduction viii 1 Scope 1 1.1 Inclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Exclusions . . . . . . . . . . . . .
9、. . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2 Conformity 3 3 Normative references 4 4 Symbols and denitions 4 4.1 Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 4.1.1 Operators and relations . . . . . . . . . . . . . . . . . . . . . . . .
10、. . . . . 4 4.1.2 Sets and intervals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 4.1.3 Exceptional values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 4.1.4 Special values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 4.1.5 The B
11、oolean datatype . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 4.1.6 Operation specication framework . . . . . . . . . . . . . . . . . . . . . . . 6 4.2 Denitions of terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 5 Specications for integer and oating p
12、oint datatypes and operations 12 5.1 Integer datatypes and operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5.1.1 Integer result function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 5.1.2 Integer operations . . . . . . . . . . . . . . . . . . . . . . . . . . .
13、 . . . . . 14 5.1.2.1 Comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 5.1.2.2 Basic arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 5.2 Floating point datatypes and operations . . . . . . . . . . . . . . . . . . . . . . . . 17 5.2.1 Conformity to IEC
14、60559 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 5.2.2 Range and granularity constants . . . . . . . . . . . . . . . . . . . . . . . . 19 5.2.3 Approximate operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 5.2.4 Rounding and rounding constants . . . . . . . . .
15、. . . . . . . . . . . . . . 20 5.2.5 Floating point result function . . . . . . . . . . . . . . . . . . . . . . . . . . 21 5.2.6 Floating point operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 5.2.6.1 Comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 5.2
16、.6.2 Basic arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 5.2.6.3 Value dissection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 5.2.6.4 Value splitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 5.3 Operations for conversion between numeric data
17、types . . . . . . . . . . . . . . . . 29 5.3.1 Integer to integer conversions . . . . . . . . . . . . . . . . . . . . . . . . . . 30 5.3.2 Floating point to integer conversions . . . . . . . . . . . . . . . . . . . . . . 31 5.3.3 Integer to oating point conversions . . . . . . . . . . . . . . . . .
18、. . . . . 31 5.3.4 Floating point to oating point conversions . . . . . . . . . . . . . . . . . . 32 5.3.5 Floating point to xed point conversions . . . . . . . . . . . . . . . . . . . . 32 5.3.6 Fixed point to oating point conversions . . . . . . . . . . . . . . . . . . . . 34 5.4 Numerals as opera
19、tions in a programming language . . . . . . . . . . . . . . . . . . 34 iii ISO/IEC 10967-1:2012(E) ISO/IEC 2012 All rights reservedBS ISO/IEC 10967-1:2012 5.4.1 Numerals for integer datatypes . . . . . . . . . . . . . . . . . . . . . . . . . 34 5.4.2 Numerals for oating point datatypes . . . . . . .
20、 . . . . . . . . . . . . . . 35 6 Notication 35 6.1 Model for handling of notications . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 6.2 Notication alternatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 6.2.1 Notication by recording in indicators . . . . . . . .
21、. . . . . . . . . . . . . 36 6.2.2 Notication by alteration of control ow . . . . . . . . . . . . . . . . . . . . 38 6.2.3 Notication by termination with message . . . . . . . . . . . . . . . . . . . 38 6.3 Delays in notication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
22、 6.4 User selection of alternative for notication . . . . . . . . . . . . . . . . . . . . . . 39 7 Relationship with language standards 39 8 Documentation requirements 41 Annex A (informative) Partial conformity 43 A.1 Integer overow notication relaxation . . . . . . . . . . . . . . . . . . . . . .
23、. . . 44 A.2 Innitary notication relaxation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 A.3 Inexact notication relaxation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 A.4 Underow notication relaxation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 A.5 Sub
24、normal values relaxation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 A.6 Accuracy relaxation for add, subtract, multiply, and divide . . . . . . . . . . . . . 45 A.7 Accuracy relaxation for oating point conversion . . . . . . . . . . . . . . . . . . . 47 Annex B (informative) IE
25、C 60559 bindings 51 B.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 B.2 Notication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Annex C (informative) Rationale 57 C.1 Scope . . . . . . . . . . . . . . . . . . . .
26、. . . . . . . . . . . . . . . . . . . . . . . 57 C.1.1 Inclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 C.1.2 Exclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 C.1.3 Companion parts to this part . . . . . . . . . . . . . .
27、. . . . . . . . . . . . 58 C.2 Conformity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 C.2.1 Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 C.3 Normative references . . . . . . . . . . . . . . . . . . . . . . . . . . . .
28、. . . . . . . 59 C.4 Symbols and denitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 C.4.1 Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 C.4.2 Denitions of terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 C.5 S
29、pecications for integer and oating point datatypes and operations . . . . . . . . 61 C.5.1 Integer datatypes and operations . . . . . . . . . . . . . . . . . . . . . . . . 62 C.5.1.0.1 Unbounded integers . . . . . . . . . . . . . . . . . . . . . 62 C.5.1.0.2 Bounded non-modulo integers . . . . . . .
30、 . . . . . . . . 63 C.5.1.0.3 Modulo integers . . . . . . . . . . . . . . . . . . . . . . . 64 C.5.1.1 Integer result function . . . . . . . . . . . . . . . . . . . . . . . . . 64 C.5.1.2 Integer operations . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 C.5.1.2.1 Comparisons . . . . . . .
31、. . . . . . . . . . . . . . . . . . 64 C.5.1.2.2 Basic arithmetic . . . . . . . . . . . . . . . . . . . . . . . 65 iv ISO/IEC 10967-1:2012(E) ISO/IEC 2012 All rights reservedBS ISO/IEC 10967-1:2012 C.5.2 Floating point datatypes and operations . . . . . . . . . . . . . . . . . . . . 65 C.5.2.0.1 Con
32、straints on the oating point parameters . . . . . . . 66 C.5.2.0.2 Radix complement oating point . . . . . . . . . . . . . . 68 C.5.2.1 Conformity to IEC 60559 . . . . . . . . . . . . . . . . . . . . . . . 68 C.5.2.1.1 Subnormal numbers . . . . . . . . . . . . . . . . . . . . . 69 C.5.2.1.2 Signed z
33、ero . . . . . . . . . . . . . . . . . . . . . . . . . . 69 C.5.2.1.3 Innities and NaNs . . . . . . . . . . . . . . . . . . . . . 69 C.5.2.2 Range and granularity constants . . . . . . . . . . . . . . . . . . . 70 C.5.2.2.1 Relations among oating point datatypes . . . . . . . . . 70 C.5.2.3 Approxima
34、te operations . . . . . . . . . . . . . . . . . . . . . . . . 71 C.5.2.4 Rounding and rounding constants . . . . . . . . . . . . . . . . . . 71 C.5.2.5 Floating point result function . . . . . . . . . . . . . . . . . . . . . 73 C.5.2.6 Floating point operations . . . . . . . . . . . . . . . . . . .
35、. . . . 73 C.5.2.6.1 Comparisons . . . . . . . . . . . . . . . . . . . . . . . . . 73 C.5.2.6.2 Basic arithmetic . . . . . . . . . . . . . . . . . . . . . . . 73 C.5.2.6.3 Value dissection . . . . . . . . . . . . . . . . . . . . . . . 74 C.5.2.6.4 Value splitting . . . . . . . . . . . . . . . . . .
36、. . . . . . 74 C.5.2.7 Levels of predictability . . . . . . . . . . . . . . . . . . . . . . . . 75 C.5.2.8 Identities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 C.5.2.9 Precision, accuracy, and error . . . . . . . . . . . . . . . . . . . . . 78 C.5.2.9.1 LIA-1 and error . . .
37、 . . . . . . . . . . . . . . . . . . . . 79 C.5.2.9.2 Empirical and modelling errors . . . . . . . . . . . . . . . 80 C.5.2.9.3 Propagation of errors . . . . . . . . . . . . . . . . . . . . 80 C.5.2.10 Extra precision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 C.5.3 Operations for
38、conversion between numeric datatypes . . . . . . . . . . . . 82 C.5.4 Numerals as operations in a programming language . . . . . . . . . . . . . 83 C.5.4.1 Numerals for integer datatypes . . . . . . . . . . . . . . . . . . . . 83 C.5.4.2 Numerals for oating point datatypes . . . . . . . . . . . . .
39、. . . 83 C.6 Notication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 C.6.1 Model handling of notications . . . . . . . . . . . . . . . . . . . . . . . . . 84 C.6.2 Notication alternatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 C.6.2.1 Notic
40、ation by recording in indicators . . . . . . . . . . . . . . . . 84 C.6.2.2 Notication by alteration of control ow . . . . . . . . . . . . . . . 85 C.6.2.3 Notication by termination with message . . . . . . . . . . . . . . 86 C.6.3 Delays in notication . . . . . . . . . . . . . . . . . . . . . . . .
41、 . . . . . . . 86 C.6.4 User selection of alternative for notication . . . . . . . . . . . . . . . . . . 86 C.7 Relationship with language standards . . . . . . . . . . . . . . . . . . . . . . . . . 87 C.8 Documentation requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Anne
42、x D (informative) Example bindings for specic languages 89 D.1 Ada . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 D.2 C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 D.3 C+ . . . . . . . . . . . . . . . . .
43、. . . . . . . . . . . . . . . . . . . . . . . . . . . 104 D.4 Fortran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 D.5 Common Lisp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Annex E (informative) Example of a conformit
44、y statement 121 E.1 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 v ISO/IEC 10967-1:2012(E) ISO/IEC 10967-1:2012(E) ISO/IEC 2012 All rights reservedBS ISO/IEC 10967-1:2012 E.2 Integer parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . .
45、 . . . . . . . . 121 E.3 Floating point parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 E.4 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 E.5 Notication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
46、. . . . . . . 122 Annex F (informative) Example programs 125 F.1 Verifying platform acceptability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 F.2 Selecting alternate code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 F.3 Terminating a loop . . . . . . . . .
47、. . . . . . . . . . . . . . . . . . . . . . . . . . . 126 F.4 Estimating error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 F.5 Saving exception state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 F.6 Fast versus accurate . . . . . . . . . .
48、 . . . . . . . . . . . . . . . . . . . . . . . . . 127 F.7 High-precision multiply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 Bibliography 129 vi ISO/IEC 10967-1:2012(E) ISO/IEC 2012 All rights reservedBS ISO/IEC 10967-1:2012 vii Foreword ISO (the International Organizatio
49、n for Standardization) and IEC (the International Electrotechnical Commission) form the specialized system for worldwide standardization. National bodies that are members of ISO or IEC participate in the development of International Standards through technical committees established by the respective organization to deal with particular fields of technical activity. ISO and IEC technical committees collaborate in fields of mutual interest. Other international organizations, governmental and non-govern