Loading [MathJax]/jax/output/HTML-CSS/config.js
Adobe Source Libraries
2.0.0
A collection of C++ libraries.
Toggle main menu visibility
Main Page
Related Pages
Topics
Namespaces
Namespace List
Namespace Members
All
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
w
x
Functions
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
w
x
Variables
Typedefs
Enumerations
Enumerator
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
y
z
~
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
z
~
Variables
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
x
y
Typedefs
_
a
b
c
d
e
f
g
h
i
k
m
n
o
p
r
s
t
v
Enumerations
Enumerator
a
c
e
h
i
l
o
p
s
v
Related Symbols
a
b
c
h
l
n
o
p
s
u
Files
File List
File Members
All
$
_
a
b
f
o
t
u
Functions
Variables
Macros
a
b
f
t
Adobe Source Libraries
Documentation Home
News
Top News
Previous News
License Information
Contributing to ASL
Contributors
Glossary of Terms
Personal Foreword
Build Instructions
Release Notes
Success Stories
Documentation
Expression Language
Types
Todo List
Deprecated List
Topics
Namespaces
Classes
Files
File List
adobe
algorithm
config
container
functional
iterator
string
to_string.hpp
test
utility
adam.hpp
adam_evaluate.hpp
adam_parser.hpp
algorithm.hpp
any_regular.hpp
any_regular_fwd.hpp
arg_stream.hpp
array.hpp
array_fwd.hpp
cassert.hpp
circular_queue.hpp
closed_hash.hpp
closed_hash_fwd.hpp
cmath.hpp
config.hpp
conversion.hpp
copy_on_write.hpp
counter.hpp
cstdint.hpp
dancing_links.hpp
dictionary.hpp
dictionary_arg_stream.hpp
dictionary_fwd.hpp
empty.hpp
enum_ops.hpp
eve.hpp
eve_evaluate.hpp
eve_parser.hpp
exception.hpp
expression_parser.hpp
extents.hpp
external_model.hpp
final.hpp
fnv.hpp
forest.hpp
function.hpp
functional.hpp
future.hpp
iomanip.hpp
iomanip_asl_cel.hpp
iomanip_fwd.hpp
iomanip_javascript.hpp
iomanip_pdf.hpp
iomanip_xml.hpp
is_range.hpp
istream.hpp
istream_fwd.hpp
iterator.hpp
json.hpp
json_helper.hpp
layout_attributes.hpp
localization.hpp
macro_utilities.hpp
manip.hpp
md5.hpp
memory.hpp
memory_fwd.hpp
mismatch.hpp
name.hpp
numeric.hpp
once.hpp
placeable_concept.hpp
poly.hpp
poly_copyable.hpp
poly_placeable.hpp
poly_regular.hpp
regular_concept.hpp
select.hpp
selection.hpp
serializable.hpp
sha.hpp
sheet.hpp
static_table.hpp
string.hpp
string_fwd.hpp
table_index.hpp
task.hpp
thread_id.hpp
timer.hpp
type_inspection.hpp
type_traits.hpp
typeinfo.hpp
unicode.hpp
utility.hpp
vector.hpp
vector_fwd.hpp
virtual_machine.hpp
widget_attributes.hpp
xml_parser.hpp
xstring.hpp
zuid.hpp
documentation
File Members
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
to_string.hpp
Go to the documentation of this file.
1
/*
2
Copyright 2012 Adobe Systems Incorporated
3
Distributed under the Boost Software License - Version 1.0 (see the accompanying file LICENSE
4
or a copy at https://stlab.github.io/adobe_source_libraries/licenses.html)
5
*/
6
7
/**************************************************************************************************/
8
9
#ifndef ADOBE_STRING_TO_STRING_HPP
10
#define ADOBE_STRING_TO_STRING_HPP
11
12
#include <algorithm>
13
#include <cfloat>
14
#include <cstdio>
15
#include <string>
16
17
#include <
adobe/cassert.hpp
>
18
19
/**************************************************************************************************/
20
21
namespace
adobe
{
22
23
/**************************************************************************************************/
24
84
85
template
<
typename
O>
// O models output iterator accepting type char
86
O
to_string
(
double
x, O out,
bool
precise =
false
) {
87
ADOBE_ASSERT
((-DBL_MAX <= x && x <= DBL_MAX) &&
88
"WARNING (sparent) : to_string() only supports finite values."
);
89
90
/*
91
longest possible string result is:
92
1 "-"
93
1 digit (will not be 0)
94
1 "."
95
16 digits (precise, 14 digits otherwise).
96
2 "e+" or "e-"
97
3 digit exponent
98
1 null
99
-------------------
100
= 25 characters
101
Use 32 as the next power-of-two for some safety with no overhead.
102
*/
103
char
buf[32];
104
105
#if defined(_MSC_VER)
106
int
size
= _snprintf_s(&buf[0],
sizeof
(buf),
sizeof
(buf),
"%.*g"
, precise ? 17 : 15, x);
107
#else
108
int
size
= std::snprintf(&buf[0],
sizeof
(buf),
"%.*g"
, precise ? 17 : 15, x);
109
ADOBE_ASSERT
(
size
<
static_cast<
int
>
(
sizeof
(buf)) &&
"WARNING (sparent) : snprintf truncated."
);
110
#endif
111
ADOBE_ASSERT
(
size
< (precise ? 25 : 23) &&
112
"WARNING (sparent) : to_string() result larger than expected."
);
113
ADOBE_ASSERT
(0 <
size
&&
"FATAL (sparent) : snprintf failed in to_string()."
);
114
115
return
std::copy(&buf[0], &buf[0] +
size
, out);
116
}
86
O
to_string
(
double
x, O out,
bool
precise =
false
) {
…
}
117
118
/**************************************************************************************************/
151
std::string
to_string
(
double
x);
152
153
/**************************************************************************************************/
154
155
}
// namespace adobe
156
157
/**************************************************************************************************/
158
159
#endif
160
161
/**************************************************************************************************/
cassert.hpp
ADOBE_ASSERT
#define ADOBE_ASSERT(p)
Definition
cassert.hpp:32
adobe::size
boost::range_size< Selection >::type size(const Selection &x)
Definition
selection_algorithms.hpp:374
adobe::to_string
O to_string(double x, O out, bool precise=false)
Convert double precision floating point numbers to ascii representation.
Definition
to_string.hpp:86
adobe
Definition
class_template.hpp:7
adobe
string
to_string.hpp
Generated by
1.14.0