Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
d9vk
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Joshua Ashton
d9vk
Commits
a91904c2
Commit
a91904c2
authored
Nov 27, 2019
by
Joshua Ashton
🐸
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[util] Implement parsing ratios from string views
parent
fcc5a6c8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
3 deletions
+29
-3
src/util/util_ratio.h
src/util/util_ratio.h
+29
-3
No files found.
src/util/util_ratio.h
View file @
a91904c2
#include <numeric>
#include <algorithm>
#include <cstdint>
#include <string>
#include <charconv>
namespace
dxvk
{
...
...
@@ -13,15 +15,39 @@ namespace dxvk {
public:
Ratio
(
T
num
,
T
denom
)
{
const
T
gcd
=
std
::
gcd
(
num
,
denom
);
set
(
num
,
denom
);
}
Ratio
(
std
::
string_view
view
)
{
set
(
0
,
0
);
size_t
colon
=
view
.
find
(
":"
);
if
(
colon
==
std
::
string_view
::
npos
)
return
;
std
::
string_view
numStr
=
view
.
substr
(
0
,
colon
);
std
::
string_view
denomStr
=
view
.
substr
(
colon
+
1
);
m_num
=
num
/
gcd
;
m_denom
=
denom
/
gcd
;
T
num
=
0
,
denom
=
0
;
std
::
from_chars
(
numStr
.
data
(),
numStr
.
data
()
+
numStr
.
size
(),
num
);
std
::
from_chars
(
denomStr
.
data
(),
denomStr
.
data
()
+
denomStr
.
size
(),
denom
);
set
(
num
,
denom
);
}
inline
T
num
()
const
{
return
m_num
;
}
inline
T
denom
()
const
{
return
m_denom
;
}
inline
bool
undefined
()
const
{
return
m_denom
==
0
;
}
inline
void
set
(
T
num
,
T
denom
)
{
const
T
gcd
=
std
::
gcd
(
num
,
denom
);
m_num
=
num
/
gcd
;
m_denom
=
denom
/
gcd
;
}
inline
bool
operator
==
(
const
Ratio
&
other
)
const
{
return
num
()
==
other
.
num
()
&&
denom
()
==
other
.
denom
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment