Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1 | // 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 sinclair | 67e79fe | 2022-04-07 14:43:05 +0000 | [diff] [blame] | 20 | namespace tint::writer { |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 21 | |
| 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 |
| 28 | std::string FloatToString(float f); |
| 29 | |
Ben Clayton | d6daefc | 2022-10-12 19:13:38 +0000 | [diff] [blame] | 30 | /// 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 |
| 36 | std::string DoubleToString(double f); |
| 37 | |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 38 | /// 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 |
| 41 | std::string FloatToBitPreservingString(float f); |
| 42 | |
Ben Clayton | d6daefc | 2022-10-12 19:13:38 +0000 | [diff] [blame] | 43 | /// 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 |
| 46 | std::string DoubleToBitPreservingString(double f); |
| 47 | |
dan sinclair | 67e79fe | 2022-04-07 14:43:05 +0000 | [diff] [blame] | 48 | } // namespace tint::writer |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 49 | |
| 50 | #endif // SRC_TINT_WRITER_FLOAT_TO_STRING_H_ |