xref: /libCEED/doc/sphinx/source/precision.md (revision 257916f8766357eb38205c54507de8baf75f531a)
1# Floating Point Precision
2
3Currently, libCEED supports two options for {code}`CeedScalar` : double and single.
4The default is to use double precision.
5Users wishing to set {code}`CeedScalar` to single precision should edit `include/ceed/types.h` and change
6
7```{literalinclude} ../../../include/ceed/types.h
8:end-at: "#include \"ceed-f64.h\""
9:language: c
10:start-at: "#include \"ceed-f64.h\""
11```
12
13to include {code}`ceed-f32.h` instead, then recompile the library.
14Tests can be run using `make test FC=` because the Fortran tests do not support single precision at this time.
15
16## Language-specific notes
17
18 - **C**: {code}`CEED_SCALAR_TYPE` will be defined to match one of the values of the {code}`CeedScalarType` {code}`enum`, and can be used for compile-time checking of {code}`CeedScalar`'s type; see, e.g., {code}`tests/t314-basis.c`.
19
20 - **Fortran**: There is no definition of {code}`CeedScalar` available in the Fortran header.  The user is responsible for ensuring that data used in Fortran code is of the correct type ({code}`real*8` or {code}`real*4`) for libCEED's current configuration.
21
22 - **Julia**: After compiling the single precision version of libCEED, instruct LibCEED.jl to use this library with the {code}`set_libceed_path!` function and restart the Julia session. LibCEED.jl will configure itself to use the appropriate type for {code}`CeedScalar`.
23
24 - **Python**: Make sure to replace the {code}`ceed-f64.h` inclusion rather than commenting it out, to guarantee that the Python bindings will pick the correct precision.
25           The {c:func}`scalar_type()` function has been added to the {code}`Ceed` class for convenience.
26           It returns a string corresponding to a numpy datatype matching that of {code}`CeedScalar`.
27
28 - **Rust**: The {code}`Scalar` type corresponds to {code}`CeedScalar`.
29
30**This is work in progress!**  The ability to use single precision is an initial step in ongoing development of mixed-precision support in libCEED.
31A current GitHub [issue](https://github.com/CEED/libCEED/issues/778) contains discussions related to this development.
32