Celeritas 0.7.0-dev.245+develop.a7be925e
Loading...
Searching...
No Matches
Public Member Functions | List of all members
celeritas::Constant Class Reference

Full-precision floating point constant with automatic precision demotion. More...

#include <Constant.hh>

Public Types

Type aliases
using real_type = double
 

Public Member Functions

constexpr Constant (real_type v)
 Explicitly construct from a full-precision value.
 
constexpr real_type value () const
 Access the value explicitly.
 
constexpr operator float () const
 Explicit conversion of stored value.
 
constexpr operator double () const
 Explicit access to stored value.
 

Detailed Description

Full-precision floating point constant with automatic precision demotion.

We want two behaviors from constants in Celeritas:

  1. They don't accidentally promote runtime arithmetic from single to double precision when compiling at a lower precision. This incurs a substantial performance penalty on GPU.
  2. We can use their full double-precision values when we need to: either in templated code or when interacting with other libraries. (For example, float(pi) > pi which can lead to errors in Geant4.)

This class stores a full-precision (double) value as its "real type" and defines explicit conversion operators that allow it to automatically convert to a lower-precision or real-precision type.

Operations with a floating point value returns a value of that precision (performed at that precision level); operations with integers return a full-precision Constant; and operations with Constants return a Constant.


The documentation for this class was generated from the following file: