Inspect floating point computations

Overview

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.

You might also like...
A fwakin floating window manager, that just works perfectly.
A fwakin floating window manager, that just works perfectly.

ewm ( Elite optimized* Window Manager ) + ewm is a very simple and lightweight floating window manager. + I will try to stay under 400 SLOC. Features

A RGB-D SLAM system for structural scenes, which makes use of point-line-plane features and the Manhattan World assumption.
A RGB-D SLAM system for structural scenes, which makes use of point-line-plane features and the Manhattan World assumption.

This repo proposes a RGB-D SLAM system specifically designed for structured environments and aimed at improved tracking and mapping accuracy by relying on geometric features that are extracted from the surrounding.

Fixed point 48.16 bit arithmetic type

fixed_math written from scratch fixed point math library in C++17 features minimum c++17 compiler required fixed point 48.16 arithmethic strong type w

RemixDB: A read- and write-optimized concurrent KV store. Fast point and range queries. Extremely low write-amplification.

REMIX and RemixDB The REMIX data structure was introduced in paper "REMIX: Efficient Range Query for LSM-trees", FAST'21. This repository maintains a

Entwine - point cloud organization for massive datasets
Entwine - point cloud organization for massive datasets

Build Status Entwine is a data organization library for massive point clouds, designed to conquer datasets of hundreds of billions of points as well a

A command line toolkit to generate maps, point clouds, 3D models and DEMs from drone, balloon or kite images. 📷
A command line toolkit to generate maps, point clouds, 3D models and DEMs from drone, balloon or kite images. 📷

An open source command line toolkit for processing aerial drone imagery. ODM turns simple 2D images into: Classified Point Clouds 3D Textured Models G

Bitcoin Point of Sale
Bitcoin Point of Sale

LNPoS Hardware https://shop.pimoroni.com/products/m5stack-faces-kit-pocket-computer-with-keyboard-game-calculator Installation Install Arduino IDE: ht

FG-Net: Fast Large-Scale LiDAR Point Clouds Understanding Network Leveraging Correlated Feature Mining and Geometric-Aware Modelling
FG-Net: Fast Large-Scale LiDAR Point Clouds Understanding Network Leveraging Correlated Feature Mining and Geometric-Aware Modelling

FG-Net: Fast Large-Scale LiDAR Point Clouds Understanding Network Leveraging Correlated Feature Mining and Geometric-Aware Modelling Comparisons of Running Time of Our Method with SOTA methods RandLA and KPConv:

Draco is a library for compressing and decompressing 3D geometric meshes and point clouds.

Draco is a library for compressing and decompressing 3D geometric meshes and point clouds. It is intended to improve the storage and transmission of 3D graphics.

Multi-GNSS Precise Point Postioning with Ambiguity Resolution

This is demo for multi-GNSS precise point positioning with ambiguity resolution (PPP-AR), which is based on RTKLIB and RTKLIB_demo5. FEATURES ppp-ar w

C++ header-only fixed-point math library

fpm A C++ header-only fixed-point math library. "fpm" stands for "fixed-point math". It is designed to serve as a drop-in replacement for floating-poi

An implementation on Fast Ground Segmentation for 3D LiDAR Point Cloud Based on Jump-Convolution-Process.
An implementation on Fast Ground Segmentation for 3D LiDAR Point Cloud Based on Jump-Convolution-Process.

An implementation on "Shen Z, Liang H, Lin L, Wang Z, Huang W, Yu J. Fast Ground Segmentation for 3D LiDAR Point Cloud Based on Jump-Convolution-Process. Remote Sensing. 2021; 13(16):3239. https://doi.org/10.3390/rs13163239"

A virtual network Differential GNSS server-client project using Precise Point Positioning (PPP). Global coverage. Without physical base station construction needed. An open-source virtual base station approach.
A virtual network Differential GNSS server-client project using Precise Point Positioning (PPP). Global coverage. Without physical base station construction needed. An open-source virtual base station approach.

Virtual-Network-DGNSS-Project This project is the software implementation for a publicly available, open-source, client/server VN-DGNSS implementation

A LiDAR point cloud cluster for panoptic segmentation
A LiDAR point cloud cluster for panoptic segmentation

Divide-and-Merge-LiDAR-Panoptic-Cluster A demo video of our method with semantic prior: More information will be coming soon! As a PhD student, I don'

A simple single point light shadow mapping with OpenGL 3.3 and C++

omni-directional-light-example Using OpenGL 3.3 with C++ Basically a single light map, no lighting model was used Usage Build the executable outside A

An implementation of ICP(Iterative Closest Point).

An implementation of ICP(Iterative Closest Point). Users can specify which dimensions of transformation to optimize.

Ground segmentation and point cloud clustering based on CVC(Curved Voxel Clustering)

my_detection Ground segmentation and point cloud clustering based on CVC(Curved Voxel Clustering) 本项目使用设置地面坡度阈值的方法,滤除地面点,使用三维弯曲体素聚类法完成点云的聚类,包围盒参数由Apol

The goal of insidesp is to do fast point in polygon classification, the sp way.

insidesp The goal of insidesp is to do fast point in polygon classification, the sp way. We are comparing a few ways of implementing this, essentially

The code implemented in ROS projects a point cloud obtained by a Velodyne VLP16 3D-Lidar sensor on an image from an RGB camera.
The code implemented in ROS projects a point cloud obtained by a Velodyne VLP16 3D-Lidar sensor on an image from an RGB camera.

PointCloud on Image The code implemented in ROS projects a point cloud obtained by a Velodyne VLP16 3D-Lidar sensor on an image from an RGB camera. Th

Comments
  • Fix segfault when using an unknown identifier

    Fix segfault when using an unknown identifier

    For example, the sin() function is not yet supported, but when trying sin(pi) it says (with UndefinedBehaviorSanitizer enabled):

    Unknown identifier 'sin(pi)'eval.c:452:23: runtime error: member access within misaligned address 0x1a9f07e9f100011f for type 'Expression' (aka 'struct Expression'), which requires 8 byte alignment
    0x1a9f07e9f100011f: note: pointer points here
    <memory cannot be printed>
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior eval.c:452:23 in
    eval.c:452:23: runtime error: load of misaligned address 0x1a9f07e9f100011f for type 'enum (anonymous enum at eval.c:11:3)', which requires 8 byte alignment
    0x1a9f07e9f100011f: note: pointer points here
    <memory cannot be printed>
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior eval.c:452:23 in
    UndefinedBehaviorSanitizer:DEADLYSIGNAL
    ==55692==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0xffff87e9f100011f (pc 0x0001001ed700 bp 0x0001001ed6fc sp 0x00016fc16fa0 T3060488)
    ==55692==The signal is caused by a UNKNOWN memory access.
        #0 0x1001ed700 in parse_verify eval.c:452
    
    ==55692==Register values:
     x[0] = 0x000000016fc16ea0   x[1] = 0x0000000000000000   x[2] = 0x0000000000000000   x[3] = 0x00000001012003d0
     x[4] = 0x6a6cb03abcebc041   x[5] = 0x0000000000000000   x[6] = 0x0000000000000000   x[7] = 0x0000000000000000
     x[8] = 0x1a9f07e9f100011f   x[9] = 0x000000000000d810  x[10] = 0x00000000000c6230  x[11] = 0x0000000000000001
    x[12] = 0x0000000000000000  x[13] = 0x00000001005b7153  x[14] = 0x0000000000000000  x[15] = 0x0000000000000000
    x[16] = 0x0000000000000049  x[17] = 0x0000000100410058  x[18] = 0x0000000000000000  x[19] = 0x0000000000000000
    x[20] = 0x0000000000000000  x[21] = 0x0000000000000000  x[22] = 0x0000000000000000  x[23] = 0x0000000000000000
    x[24] = 0x0000000000000000  x[25] = 0x0000000000000000  x[26] = 0x0000000000000000  x[27] = 0x0000000000000000
    x[28] = 0x000000016fc177c8     fp = 0x000000016fc170a0     lr = 0x00000001001ed6fc     sp = 0x000000016fc16fa0
    UndefinedBehaviorSanitizer can not provide additional info.
    SUMMARY: UndefinedBehaviorSanitizer: SEGV eval.c:452 in parse_verify
    ==55692==ABORTING
    

    This turns out to be due to parse_primary() returning true for unknown identifiers. Return false instead, and add a newline to the error message, similar to the other errors in this function.

    opened by DimitryAndric 0
Owner
Dale Weiler
Digital media specialist, graphics programmer and software engineer
Dale Weiler
LIDAR(Livox Horizon) point cloud preprocessing, including point cloud filtering and point cloud feature extraction (edge points and plane points)

LIDAR(Livox Horizon) point cloud preprocessing, including point cloud filtering and point cloud feature extraction (edge points and plane points)

hongyu wang 12 Dec 28, 2022
Calculator that suffers from floating point precision

calc A calculator that suffers from floating precision. This calculator suffers from floating point precision and isn't much more than a fun project.

atiedebee 1 Nov 28, 2021
Tests to check the determinism of the basic floating point arithmetic operations on different devices, using Unity and Rust.

This repo contains tests to check the determinism (consistency) of the basic floating point arithmetic operations (add, subtract, multiply, divide) on

Erik Roystan 9 Dec 20, 2022
A composable container for Adaptive ROS 2 Node computations. Select between FPGA, CPU or GPU at run-time.

adaptive_component A composable stateless container for Adaptive ROS 2 Node computations. Select between FPGA, CPU or GPU at run-time. Nodes using har

ROS 2 Hardware Acceleration Working Group 7 Sep 9, 2022
Inspect C++ memory in the browser

incppect Inspect C++ memory in the browser Description This is a small library that allows a C++ native application to stream memory bits to one or mo

Georgi Gerganov 50 Dec 29, 2022
Apache Thrift is a lightweight, language-independent software stack for point-to-point RPC implementation

Apache Thrift Introduction Thrift is a lightweight, language-independent software stack for point-to-point RPC implementation. Thrift provides clean a

The Apache Software Foundation 9.5k Jan 7, 2023
floating patches for rusty_v8

V8 JavaScript Engine V8 is Google's open source JavaScript engine. V8 implements ECMAScript as specified in ECMA-262. V8 is written in C++ and is used

Deno Land 52 Nov 3, 2022
tabbed window manager that can tile windows inside floating containers

tabbed window manager that can tile windows inside floating containers

Seninha 131 Dec 27, 2022
A simple floating clock for Linux

Hoverclock Hoverclock is a simple, yet customizable floating clock for Linux created with QT. Table of contents General info Technologies Quick note U

Kostoski Stefan 13 Sep 13, 2022
tabbed window manager that can tile windows inside floating containers

shod ┌───────────────────────┐ │ │ ┌─────┼────

Seninha 133 Jan 5, 2023