1 # Floating-Point Arithmetic Critic Framework (IEEE 754)
3 This framework guides the Critic role when evaluating floating-point code, algorithms, and implementations from the perspective of the IEEE Standard for Floating-Point Arithmetic (IEEE 754). The critic focuses on standard compliance, numerical correctness, portability, robustness, and the principles that ensure reliable, predictable, and efficient floating-point computation.
5 ## Floating-Point Code Evaluation Areas
7 ### 1. Standard Compliance and Conformance
9 - Adherence to IEEE 754 requirements for formats and operations
10 - Correct use of standard floating-point types and representations
11 - Proper handling of special values (NaN, infinities, signed zeros)
12 - Correct implementation of rounding modes and exceptions
13 - Avoidance of non-standard or implementation-defined behavior
16 - Ignoring or mishandling NaN, infinity, or signed zero
17 - Relying on platform-specific floating-point extensions
18 - Incorrect rounding or exception handling
19 - Violating standard arithmetic rules (e.g., associativity, distributivity)
20 - Failing to document or control non-standard behaviors
22 **Evaluation Questions:**
23 - Does the code conform to IEEE 754 for all floating-point operations?
24 - Are special values (NaN, infinities, signed zeros) handled correctly?
25 - Are rounding modes and exceptions managed as required?
26 - Is non-standard behavior avoided or clearly documented?
27 - Does the code produce consistent results across conforming platforms?
29 ### 2. Numerical Accuracy and Correctness
31 - Proper management of rounding errors and loss of significance
32 - Use of numerically stable algorithms
33 - Avoidance of catastrophic cancellation
34 - Correct handling of subnormal numbers
35 - Awareness of precision limits and error propagation
38 - Accumulation of rounding errors
39 - Loss of significance in subtraction of nearly equal numbers
40 - Ignoring the effects of finite precision
41 - Failing to use stable algorithms for summation, dot products, etc.
42 - Not accounting for subnormal number behavior
44 **Evaluation Questions:**
45 - Are algorithms chosen for numerical stability?
46 - Is rounding error analyzed and minimized?
47 - Are subnormal numbers handled or avoided as appropriate?
48 - Is error propagation considered and documented?
49 - Are results validated against analytical or high-precision references?
51 ### 3. Exception Handling and Robustness
53 - Detection and handling of floating-point exceptions (overflow, underflow, division by zero, invalid operation, inexact)
54 - Use of exception flags and status checks
55 - Graceful handling of exceptional results
56 - Resource cleanup and error reporting on exceptions
57 - Consistent exception handling across platforms
60 - Ignoring floating-point exceptions
61 - Unchecked propagation of NaN or infinity
62 - Inconsistent or missing error handling for exceptional cases
63 - Failing to clear or check exception flags
64 - Platform-dependent exception behavior
66 **Evaluation Questions:**
67 - Are all floating-point exceptions detected and handled?
68 - Are exception flags checked and cleared as needed?
69 - Is error reporting clear and consistent?
70 - Are exceptional results (NaN, infinity) handled gracefully?
71 - Is exception handling portable across platforms?
73 ### 4. Portability and Implementation Independence
75 - Use of standard floating-point types and operations
76 - Avoidance of platform-specific or non-standard features
77 - Correct handling of endianness and representation
78 - Use of feature test macros or runtime checks for optional features
79 - Documentation of implementation dependencies
82 - Assuming specific floating-point formats or representations
83 - Using non-portable intrinsics or assembly
84 - Failing to account for differences in rounding or exception handling
85 - Ignoring endianness in binary data exchange
86 - Missing feature detection for optional IEEE 754 features
88 **Evaluation Questions:**
89 - Does the code avoid assumptions about floating-point representation?
90 - Are platform-specific features properly abstracted or guarded?
91 - Is endianness handled correctly for binary data?
92 - Are all implementation dependencies documented?
93 - Does the code behave consistently across IEEE 754-compliant systems?
95 ### 5. Performance and Efficiency
97 - Efficient use of floating-point operations and hardware
98 - Minimization of unnecessary conversions or type changes
99 - Use of fused operations (e.g., FMA) where appropriate
100 - Avoidance of performance pitfalls (e.g., denormal number slowdowns)
101 - Proper use of compiler optimization flags for floating-point
104 - Excessive type conversions or mixed-precision operations
105 - Inefficient algorithms for floating-point computation
106 - Unintentional performance loss due to subnormal numbers
107 - Missing opportunities for hardware acceleration (e.g., FMA)
108 - Over-optimization at the expense of correctness
110 **Evaluation Questions:**
111 - Are floating-point operations used efficiently?
112 - Are fused or hardware-accelerated operations leveraged where possible?
113 - Is performance balanced with numerical correctness?
114 - Are performance bottlenecks due to floating-point identified and addressed?
115 - Are compiler flags for floating-point optimization used appropriately?
117 ## IEEE 754 Standards-Specific Criticism Process
119 ### Step 1: Standard Conformance Analysis
120 1. **Check Format Compliance**: Are all floating-point types and operations IEEE 754-compliant?
121 2. **Evaluate Special Value Handling**: Are NaN, infinities, and signed zeros handled per standard?
122 3. **Assess Rounding and Exceptions**: Are rounding modes and exceptions managed as required?
123 4. **Review Implementation Dependencies**: Are non-standard behaviors documented?
125 ### Step 2: Numerical Accuracy Assessment
126 1. **Audit Algorithm Stability**: Are numerically stable algorithms used?
127 2. **Check Rounding Error Management**: Is rounding error analyzed and minimized?
128 3. **Evaluate Subnormal and Edge Case Handling**: Are subnormals and edge cases handled correctly?
129 4. **Assess Error Propagation**: Is error propagation considered and documented?
131 ### Step 3: Exception Handling Analysis
132 1. **Check Exception Detection**: Are all floating-point exceptions detected?
133 2. **Evaluate Exception Handling**: Are exceptions handled and reported consistently?
134 3. **Assess Resource Cleanup**: Are resources cleaned up on exception paths?
135 4. **Review Exception Documentation**: Are exceptional conditions clearly documented?
137 ## IEEE 754 Standards-Specific Criticism Guidelines
139 ### Focus on Specification Compliance
141 - "This code does not propagate NaN as required by IEEE 754."
142 - "The rounding mode is not set or restored as required by the standard."
143 - "This operation does not raise the inexact exception when it should."
144 - "The handling of signed zero is not compliant with IEEE 754 rules."
147 - "This seems wrong."
148 - "I don't like how this handles errors."
149 - "This might not work everywhere."
151 ### Emphasize Numerical Correctness and Robustness
153 - "This subtraction is subject to catastrophic cancellation."
154 - "The summation algorithm is not numerically stable."
155 - "This code does not check for overflow or underflow."
156 - "The propagation of NaN and infinity is not handled consistently."
159 - "This is inaccurate."
160 - "This could be better."
161 - "This is not robust."
163 ### Consider Portability and Implementation Quality
165 - "This code assumes a specific floating-point format, which limits portability."
166 - "The use of platform-specific intrinsics is not properly guarded."
167 - "Endianness is not handled for binary floating-point data."
168 - "The code does not document its reliance on non-standard features."
171 - "This is not portable."
172 - "This might break on other systems."
173 - "This is platform-dependent."
175 ## IEEE 754 Standards-Specific Problem Categories
177 ### Standard Compliance Problems
178 - **Non-Standard Operations**: Use of operations not defined by IEEE 754
179 - **Special Value Mishandling**: Incorrect handling of NaN, infinity, or signed zero
180 - **Rounding Mode Violations**: Failing to set or respect rounding modes
181 - **Exception Handling Omissions**: Not detecting or reporting floating-point exceptions
183 ### Numerical Accuracy Problems
184 - **Rounding Error Accumulation**: Unchecked accumulation of rounding errors
185 - **Catastrophic Cancellation**: Loss of significance in subtraction or addition
186 - **Unstable Algorithms**: Use of numerically unstable methods
187 - **Subnormal Mishandling**: Ignoring or mishandling subnormal numbers
189 ### Exception Handling Problems
190 - **Unchecked Exceptions**: Failing to detect or handle floating-point exceptions
191 - **NaN/Infinity Propagation**: Unchecked propagation of special values
192 - **Inconsistent Exception Handling**: Different handling patterns in similar contexts
193 - **Missing Error Reporting**: Lack of clear error information for exceptional results
195 ### Portability Problems
196 - **Format Assumptions**: Assuming specific floating-point formats or layouts
197 - **Platform-Specific Features**: Use of non-portable intrinsics or extensions
198 - **Endianness Issues**: Failing to handle endianness in binary data
199 - **Missing Feature Detection**: No checks for optional IEEE 754 features
201 ## IEEE 754 Standards-Specific Criticism Templates
203 ### For Standard Compliance Issues
205 Standard Compliance Issue: [Specific IEEE 754 violation]
206 Standard Reference: [IEEE 754 section and paragraph]
207 Problem: [How this violates the standard specification]
208 Impact: [Incorrect results, non-portability, or non-conformance]
209 Evidence: [Specific code examples and standard citations]
210 Priority: [Critical/High/Medium/Low]
213 ### For Numerical Accuracy Issues
215 Numerical Accuracy Issue: [Specific numerical problem]
216 Problem: [What makes this inaccurate or unstable]
217 Impact: [Loss of precision, incorrect results, or instability]
218 Evidence: [Specific code paths and failure scenarios]
219 Priority: [Critical/High/Medium/Low]
222 ### For Exception Handling Issues
224 Exception Handling Issue: [Specific exception handling problem]
225 Problem: [What makes this unsafe or incorrect]
226 Impact: [Potential crashes, silent errors, or undefined results]
227 Evidence: [Specific code examples and exception scenarios]
228 Priority: [Critical/High/Medium/Low]
231 ### For Portability Issues
233 Portability Issue: [Specific portability problem]
234 Problem: [What assumptions or dependencies limit portability]
235 Impact: [Platforms or implementations where this will fail]
236 Evidence: [Specific code examples and platform differences]
237 Priority: [High/Medium/Low]
240 ## IEEE 754 Standards-Specific Criticism Best Practices
243 - **Cite Standard References**: Always reference specific sections of IEEE 754
244 - **Focus on Specification**: Evaluate against the formal floating-point standard
245 - **Consider All Implementations**: Think about all conforming platforms, not just one
246 - **Emphasize Correctness**: Prioritize correct results and predictable behavior
247 - **Document Dependencies**: Clearly identify any implementation-defined behaviors
250 - **Assume Specific Implementations**: Don't assume particular hardware or compiler behavior
251 - **Ignore Special Values**: Don't overlook NaN, infinity, or signed zero
252 - **Accept Silent Errors**: Don't tolerate code that ignores exceptions or errors
253 - **Skip Error Checking**: Don't ignore exception handling requirements
254 - **Overlook Portability**: Don't accept unnecessarily non-portable code
256 ## IEEE 754 Standards-Specific Criticism Checklist
258 ### Standard Compliance Assessment
259 - [ ] Does the code conform to IEEE 754 for all floating-point operations?
260 - [ ] Are all special values (NaN, infinities, signed zeros) handled correctly?
261 - [ ] Are rounding modes and exceptions managed as required?
262 - [ ] Are non-standard behaviors documented?
263 - [ ] Does the code produce consistent results across platforms?
265 ### Numerical Accuracy Assessment
266 - [ ] Are numerically stable algorithms used?
267 - [ ] Is rounding error analyzed and minimized?
268 - [ ] Are subnormal numbers handled or avoided as appropriate?
269 - [ ] Is error propagation considered and documented?
270 - [ ] Are results validated against references?
272 ### Exception Handling Assessment
273 - [ ] Are all floating-point exceptions detected and handled?
274 - [ ] Are exception flags checked and cleared as needed?
275 - [ ] Is error reporting clear and consistent?
276 - [ ] Are exceptional results handled gracefully?
277 - [ ] Is exception handling portable across platforms?
279 ### Portability Assessment
280 - [ ] Does the code avoid assumptions about floating-point representation?
281 - [ ] Are platform-specific features properly abstracted or guarded?
282 - [ ] Is endianness handled correctly for binary data?
283 - [ ] Are all implementation dependencies documented?
284 - [ ] Does the code behave consistently across IEEE 754-compliant systems?
286 ## IEEE 754 Standards-Specific Evaluation Questions
288 ### For Any Floating-Point Code
289 1. **Does this code conform to the IEEE 754 standard for all operations?**
290 2. **Are all special values (NaN, infinities, signed zeros) handled correctly?**
291 3. **Is numerical accuracy and stability ensured?**
292 4. **Are all floating-point exceptions detected and handled?**
293 5. **Is the code portable across conforming implementations?**
294 6. **Are all floating-point operations efficient and correct?**
295 7. **Is error propagation and reporting handled appropriately?**
296 8. **Are all implementation dependencies documented?**
297 9. **Do all code paths handle exceptional results and cleanup resources?**
298 10. **Is the code optimized for performance without sacrificing correctness?**
300 ### For Library or System Code
301 1. **Are all public interfaces documented with floating-point behavior and exceptions?**
302 2. **Is thread safety clearly specified and implemented for floating-point state?**
303 3. **Are all parameters validated for valid floating-point values?**
304 4. **Is the API design consistent with IEEE 754 conventions?**
305 5. **Are all resources and exceptional states properly managed?**
307 ## IEEE 754 Principles Applied
309 ### "Provide a Standardized Floating-Point Model"
310 - Use standard formats and operations for portability and predictability
311 - Avoid reliance on non-standard or implementation-specific features
312 - Ensure consistent results across conforming platforms
314 ### "Support Special Values and Exceptions"
315 - Correctly handle NaN, infinities, and signed zeros
316 - Detect and manage all floating-point exceptions
317 - Propagate special values as required by the standard
319 ### "Enable Numerical Robustness"
320 - Use numerically stable algorithms
321 - Minimize and analyze rounding errors
322 - Avoid catastrophic cancellation and instability
324 ### "Balance Performance and Correctness"
325 - Use efficient algorithms and hardware features
326 - Optimize only when correctness is not compromised
327 - Leverage fused operations where appropriate
329 ### "Document and Control Implementation Dependencies"
330 - Clearly document any reliance on non-standard features
331 - Use feature detection and abstraction for portability
332 - Avoid silent or undocumented deviations from the standard
334 ## Floating-Point Library and API Evaluation Criteria
336 ### Arithmetic Functions
337 - **Addition/Subtraction**: Correct rounding, cancellation handling, special value propagation
338 - **Multiplication/Division**: Overflow/underflow detection, correct sign handling, fused multiply-add where available
339 - **Square Root, Remainder, etc.**: Domain error handling, correct result for special values
341 ### Conversion Functions
342 - **Integer/Floating-Point Conversions**: Correct rounding, overflow/underflow detection, exception raising
343 - **String Conversions**: Accurate parsing/formatting, error detection, locale awareness
345 ### Comparison Functions
346 - **Equality/Ordering**: Correct handling of NaN, signed zero, and infinities
347 - **Total Ordering**: Use of totalOrder predicate where required
349 ### Mathematical Functions
350 - **Transcendentals (exp, log, sin, etc.)**: Correct domain/range, error handling, special value propagation
351 - **Error Analysis**: Documentation of accuracy, error bounds, and limitations
353 ### Exception and Status Functions
354 - **Exception Flags**: Setting, clearing, and querying exception status
355 - **Rounding Modes**: Setting and restoring rounding modes as required
356 - **Status Reporting**: Clear and consistent reporting of floating-point state