source: cpp/PrintFloat/PrintFloat.h @ 1257

Last change on this file since 1257 was 823, checked in by Maciej Komosinski, 6 years ago

Added "PrintFloat?" implementation of the Dragon4 algorithm, since C++ still lacks built-in "intelligent" printing of floating point values with full precision

File size: 3.3 KB
Line 
1/******************************************************************************
2  Copyright (c) 2014 Ryan Juckett
3  http://www.ryanjuckett.com/
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14     claim that you wrote the original software. If you use this software
15     in a product, an acknowledgment in the product documentation would be
16     appreciated but is not required.
17 
18  2. Altered source versions must be plainly marked as such, and must not be
19     misrepresented as being the original software.
20 
21  3. This notice may not be removed or altered from any source
22     distribution.
23******************************************************************************/
24
25#ifndef RJ__PrintFloat_h
26#define RJ__PrintFloat_h
27
28#include "Standard.h"
29
30//******************************************************************************
31//******************************************************************************
32enum tPrintFloatFormat
33{
34    PrintFloatFormat_Positional,    // [-]ddddd.dddd
35    PrintFloatFormat_Scientific,    // [-]d.dddde[sign]ddd
36};
37 
38//******************************************************************************
39// Print a 32-bit floating-point number as a decimal string.
40// The output string is always NUL terminated and the string length (not
41// including the NUL) is returned.
42//******************************************************************************
43tU32 PrintFloat32
44(
45    tC8 *               pOutBuffer,     // buffer to output into
46    tU32                bufferSize,     // size of pOutBuffer
47    tF32                value,          // value to print
48    tPrintFloatFormat   format,         // format to print with
49    tS32                precision       // If negative, the minimum number of digits to represent a
50                                        // unique 32-bit floating point value is output. Otherwise,
51                                        // this is the number of digits to print past the decimal point.
52);
53 
54//******************************************************************************
55// Print a 64-bit floating-point number as a decimal string.
56// The output string is always NUL terminated and the string length (not
57// including the NUL) is returned.
58//******************************************************************************
59tU32 PrintFloat64
60(
61    tC8 *               pOutBuffer,     // buffer to output into
62    tU32                bufferSize,     // size of pOutBuffer
63    tF64                value,          // value to print
64    tPrintFloatFormat   format,         // format to print with
65    tS32                precision       // If negative, the minimum number of digits to represent a
66                                        // unique 64-bit floating point value is output. Otherwise,
67                                        // this is the number of digits to print past the decimal point.
68);
69
70#endif
71
Note: See TracBrowser for help on using the repository browser.