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_WRITER_FLOAT_TO_STRING_H_ 16 #define SRC_WRITER_FLOAT_TO_STRING_H_ 17 18 #include <string> 19 20 namespace tint { 21 namespace writer { 22 23 /// Converts the float `f` to a string using fixed-point notation (not 24 /// scientific). The float will be printed with the full precision required to 25 /// describe the float. All trailing `0`s will be omitted after the last 26 /// non-zero fractional number, unless the fractional is zero, in which case the 27 /// number will end with `.0`. 28 /// @return the float f formatted to a string 29 std::string FloatToString(float f); 30 31 /// Converts the float `f` to a string, using hex float notation for infinities, 32 /// NaNs, or subnormal numbers. Otherwise behaves as FloatToString. 33 /// @return the float f formatted to a string 34 std::string FloatToBitPreservingString(float f); 35 36 } // namespace writer 37 } // namespace tint 38 39 #endif // SRC_WRITER_FLOAT_TO_STRING_H_ 40