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