• Stars
    star
    135
  • Rank 261,204 (Top 6 %)
  • Language
    C
  • License
    MIT License
  • Created almost 3 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Inspect floating point computations

Floating point expression inspector

The following tool lets you inspect the computational flow of a floating point expression, seeing where rounding occurs, when exceptions are triggered, when precision may be lost, when special values propagate, when error accumulates, and other floating point headaches.

Example

[fpinspect]# ./fpinspect "sqrt(45.0*e+phi)/pi"
Exception: 0 (1 roundings) INEXACT (45.000000 * e)
  Trace (1 operations) MUL

Exception: 0 (1 roundings) INEXACT phi
  Trace (1 operations) MUL

Exception: 0 (2 roundings) INEXACT ((45.000000 * e) + phi)
Exception: 1 (2 roundings) INEXACT ((45.000000 * e) + phi)
  Trace (2 operations) MUL ADD

Exception: 0 (3 roundings) INEXACT sqrt(((45.000000 * e) + phi))
Exception: 1 (3 roundings) INEXACT sqrt(((45.000000 * e) + phi))
Exception: 2 (3 roundings) INEXACT sqrt(((45.000000 * e) + phi))
  Trace (3 operations) MUL ADD ADD

Exception: 0 (3 roundings) INEXACT pi
Exception: 1 (3 roundings) INEXACT pi
Exception: 2 (3 roundings) INEXACT pi
  Trace (3 operations) MUL ADD ADD

Exception: 0 (4 roundings) INEXACT (sqrt(((45.000000 * e) + phi)) / pi)
Exception: 1 (4 roundings) INEXACT (sqrt(((45.000000 * e) + phi)) / pi)
Exception: 2 (4 roundings) INEXACT (sqrt(((45.000000 * e) + phi)) / pi)
Exception: 3 (4 roundings) INEXACT (sqrt(((45.000000 * e) + phi)) / pi)
  Trace (4 operations) MUL ADD ADD DIV

(sqrt(((45.000000 * e) + phi)) / pi)
        ans: 3.54370117187500
        err: 0.00000126456894

As you can see, the expression sqrt(45.0*e+phi)/pi produces a lot of output, each empty-line-separated region is a subexpression which triggered an exception, in this case because 45 * e is an inexact value, the inexact exception is presented first. Here you can see that such an expression involved 1 operations, total and in this case the operation is just a MUL. We can also see that the resulting expression, because it's inexact, incurred one rounding.

Following down the exception list, we can see that the exception propagated to phi in a MUL (which is also an inexact value), and continued, with each new inexact subexpression resulting in several roundings. Since kernels like sqrt might themselves use operations like add, we also see the final group of exceptions contains an additional ADD in it's trace.

The final result of the expression is given in ans: and below that you will find the accumulative error err: of evaluating that expression, in this case this function is exact to five mantissa digits of precision, out of a total of seven, which means this expression has ~0.71 ULP of error.

Documentation

Run the program with no expression or -h to see the options.

Here's some constants and functions available for use in expressions.

Constants

  • e
  • pi
  • phi

Functions

  • floor
  • ceil
  • trunc
  • sqrt
  • abs
  • min
  • max
  • copysign

How it works

This program implements IEEE-754 floating point completely in software, emulating all rounding modes, exceptions, and tininess detection methods which can be configured when evaluating an expression. With exception to transcendental functions, all floating point computation is also accurate to <= 1 ULP of error.

Currently there is support for 32-bit single-precision floating-point float32.{h,c} and 64-bit double-precision floating-point float64.{h,c}, as double-precision is necessary for 32-bit single-precision kernels kernel32.{h,c} to produce correctly rounded and truncated results to <= 1 ULP of error.

64-bit double-precision floating-point makes use of 128-bit modular arithmetic implemented in uint128.{h,c}

Accumulative error accounting is handled by real32.{h,c} and real64.{h,c} for single-precision and double-precision floating-point, respectively.

NOTE:

There are currently no 64-bit kernels, as that would require either 80-bit extended-precision floating-point, or 128-bit quadruple-precision floating-point to be implemented in software to have the precision necessary to produce correctly rounded and truncated results to <= 1 ULP of error.

More Repositories

1

incbin

Include binary files in C/C++
C
918
star
2

moreram

Get more system memory
C
802
star
3

breaking_the_physical_limits_of_fonts

Breaking the physical limits of fonts
JavaScript
319
star
4

glsl-parser

A GLSL parser
C++
247
star
5

lambdapp

Anonymous functions in C
C
246
star
6

gmqcc

An Improved Quake C Compiler
C++
155
star
7

normals_revisited

revisiting a known normal transformation in computer graphics
148
star
8

codin

Odin to C compiler
C
137
star
9

cvec

No bullshit vector library for C
C
78
star
10

neothyne

Engine and game
C++
76
star
11

libintrusive

Intrusive data structures for C
C
54
star
12

NVFC

OpenSource tool for monitoring, configuring and overclocking NVIDIA GPUs
C
44
star
13

scope_stack_alloc

A scoped stack allocator
C++
36
star
14

deshade

dump and replace shaders of any OpenGL or Vulkan application
C++
29
star
15

gml

Dynamically typed, higher-order, semi-functional, interpreted and embeddable programming language
C
28
star
16

0xABAD1DEA

Static global objects with constructors and destructors made useful in C++
C++
27
star
17

fibers

The fiber sourcebook
HTML
21
star
18

smbf

Static model binary format
C++
19
star
19

gmrtdxt

Realtime DXT compressor and optimizer
C++
19
star
20

fpot

Fast Point Overlap Test
C
17
star
21

dep_sort

Generic topological sorting for sorting a list of dependencies in C++17
C++
13
star
22

wfstd

Standard library I developed while working for Wayforward
C
11
star
23

vector_benchmark

Benchmarking a trivial replacement for std::vector
C++
11
star
24

alice

A barebones kernel for i386
C
10
star
25

redroid

The ultimate IRC bot
C
9
star
26

bbgl

OpenGL Rendering as a seperate process (Black Box)
C
9
star
27

lua-vec

highly efficent, caching, copy-on-write lua vector math library
Lua
7
star
28

printer-display

Use your printer as a display
C
7
star
29

odin_review

A review of the Odin programming language
HTML
6
star
30

pastes

Just a place where I store my pastes
C
6
star
31

discord-rogue

A tiny rogue like for Discord on nodejs
JavaScript
6
star
32

pds2tc

Public domain S2TC implementation
C
5
star
33

aau

Almost Always Unsigned
HTML
5
star
34

Kaizen

a small, embeddable continous integration framework for small projects
C
4
star
35

libpartial

Partially applied functions for C
C
4
star
36

xcpumemperf

Benchmark to determine cross CPU memory performance for UNIX/POSIX systems
C
3
star
37

zbar-lite

Stripped down light weight version of the zbar library
C
3
star
38

aoc

advent of code 2018 solutions https://adventofcode.com/
C++
3
star
39

glsl-compiler

GLSL compiler targeting a simple SSA IR
3
star
40

smm_video_scraper

Scrape level codes from SMM videos
Python
3
star
41

nra

patch games for nes mini and snes mini to use retroarch cores automatically
C
2
star
42

CV

CV, resume of @graphitemaster
1
star