Gemmi C++ API
Loading...
Searching...
No Matches
gemmi
include
gemmi
atof.hpp
Go to the documentation of this file.
1
// Copyright 2020 Global Phasing Ltd.
2
//
3
// Functions that convert string to floating-point number ignoring locale.
4
// Simple wrappers around fastfloat::from_chars().
5
6
#ifndef GEMMI_ATOF_HPP_
7
#define GEMMI_ATOF_HPP_
8
9
#include "
atox.hpp
"
// for is_space
10
#include "third_party/fast_float.h"
11
12
namespace
gemmi
{
13
14
using
fast_float::from_chars_result;
15
16
inline
from_chars_result
fast_from_chars
(
const
char
* start,
const
char
* end,
double
&
d
) {
17
while
(start < end &&
is_space
(*start))
18
++start;
19
if
(start < end && *start ==
'+'
)
20
++start;
21
return
fast_float::from_chars(start, end,
d
);
22
}
23
24
inline
from_chars_result
fast_from_chars
(
const
char
* start,
double
&
d
) {
25
while
(
is_space
(*start))
26
++start;
27
if
(*start ==
'+'
)
28
++start;
29
return
fast_float::from_chars(start, start + std::strlen(start),
d
);
30
}
31
32
inline
double
fast_atof
(
const
char
*
p
,
const
char
**
endptr
=
nullptr
) {
33
double
d
= 0;
34
auto
result
=
fast_from_chars
(
p
,
d
);
35
if
(
endptr
)
36
*
endptr
=
result
.ptr;
37
return
d
;
38
}
39
40
}
// namespace gemmi
41
#endif
atox.hpp
gemmi
Definition
addends.hpp:12
gemmi::fast_atof
double fast_atof(const char *p, const char **endptr=nullptr)
Definition
atof.hpp:32
gemmi::fast_from_chars
from_chars_result fast_from_chars(const char *start, const char *end, double &d)
Definition
atof.hpp:16
gemmi::is_space
bool is_space(char c)
Definition
atox.hpp:23
gemmi::HklValue
Definition
asudata.hpp:97
Generated by
1.9.8