blob: 387c0a848391ed1bf82305a2b7169b195bb863e9 [file] [log] [blame]
Ryan Harrisondbc13af2022-02-21 15:19:07 +00001// Copyright 2020 The Tint Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef SRC_TINT_WRITER_FLOAT_TO_STRING_H_
16#define SRC_TINT_WRITER_FLOAT_TO_STRING_H_
17
18#include <string>
19
dan sinclair67e79fe2022-04-07 14:43:05 +000020namespace tint::writer {
Ryan Harrisondbc13af2022-02-21 15:19:07 +000021
22/// Converts the float `f` to a string using fixed-point notation (not
23/// scientific). The float will be printed with the full precision required to
24/// describe the float. All trailing `0`s will be omitted after the last
25/// non-zero fractional number, unless the fractional is zero, in which case the
26/// number will end with `.0`.
27/// @return the float f formatted to a string
28std::string FloatToString(float f);
29
Ben Claytond6daefc2022-10-12 19:13:38 +000030/// Converts the double `f` to a string using fixed-point notation (not
31/// scientific). The double will be printed with the full precision required to
32/// describe the double. All trailing `0`s will be omitted after the last
33/// non-zero fractional number, unless the fractional is zero, in which case the
34/// number will end with `.0`.
35/// @return the double f formatted to a string
36std::string DoubleToString(double f);
37
Ryan Harrisondbc13af2022-02-21 15:19:07 +000038/// Converts the float `f` to a string, using hex float notation for infinities,
39/// NaNs, or subnormal numbers. Otherwise behaves as FloatToString.
40/// @return the float f formatted to a string
41std::string FloatToBitPreservingString(float f);
42
Ben Claytond6daefc2022-10-12 19:13:38 +000043/// Converts the double `f` to a string, using hex double notation for infinities,
44/// NaNs, or subnormal numbers. Otherwise behaves as FloatToString.
45/// @return the double f formatted to a string
46std::string DoubleToBitPreservingString(double f);
47
dan sinclair67e79fe2022-04-07 14:43:05 +000048} // namespace tint::writer
Ryan Harrisondbc13af2022-02-21 15:19:07 +000049
50#endif // SRC_TINT_WRITER_FLOAT_TO_STRING_H_