Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Leibner
dune-common
Commits
ff76b2ab
Commit
ff76b2ab
authored
15 years ago
by
Markus Blatt
Browse files
Options
Downloads
Patches
Plain Diff
Added conversion to double
[[Imported from SVN: r5714]]
parent
8624cecb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dune/common/bigunsignedint.hh
+22
-1
22 additions, 1 deletion
dune/common/bigunsignedint.hh
dune/common/test/bigunsignedinttest.cc
+6
-22
6 additions, 22 deletions
dune/common/test/bigunsignedinttest.cc
with
28 additions
and
23 deletions
dune/common/bigunsignedint.hh
+
22
−
1
View file @
ff76b2ab
...
...
@@ -124,6 +124,7 @@ namespace Dune
//! export to other types
// operator unsigned int () const;
unsigned
int
touint
()
const
;
double
todouble
()
const
;
friend
class
bigunsignedint
<
k
/
2
>
;
friend
class
std
::
numeric_limits
<
bigunsignedint
<
k
>
>
;
...
...
@@ -141,7 +142,9 @@ namespace Dune
// Constructors
template
<
int
k
>
bigunsignedint
<
k
>::
bigunsignedint
()
{
}
{
assign
(
0u
);
}
template
<
int
k
>
bigunsignedint
<
k
>::
bigunsignedint
(
int
y
)
...
...
@@ -175,6 +178,24 @@ namespace Dune
return
(
digit
[
1
]
<<
bits
)
+
digit
[
0
];
}
template
<
int
k
>
inline
double
bigunsignedint
<
k
>::
todouble
()
const
{
int
firstInZeroRange
=
n
;
for
(
int
i
=
n
-
1
;
i
>=
0
;
--
i
)
if
(
digit
[
i
]
!=
0
)
break
;
else
--
firstInZeroRange
;
int
representableDigits
=
std
::
numeric_limits
<
double
>::
digits
/
bits
;
int
lastInRepresentableRange
=
0
;
if
(
representableDigits
<
firstInZeroRange
)
lastInRepresentableRange
=
firstInZeroRange
-
representableDigits
;
double
val
=
0
;
for
(
int
i
=
firstInZeroRange
-
1
;
i
>=
lastInRepresentableRange
;
--
i
)
val
=
val
*
(
1
<<
bits
)
+
digit
[
i
];
return
val
*
(
1
<<
(
bits
*
lastInRepresentableRange
));
}
// print
template
<
int
k
>
inline
void
bigunsignedint
<
k
>::
print
(
std
::
ostream
&
s
)
const
...
...
This diff is collapsed.
Click to expand it.
dune/common/test/bigunsignedinttest.cc
+
6
−
22
View file @
ff76b2ab
...
...
@@ -47,25 +47,8 @@ int main()
Dune
::
bigunsignedint
<
100
>
a
,
b
,
c
;
a
=
100
;
int
ret
=
0
;
if
(
a
.
touint
()
!=
100
)
{
std
::
cerr
<<
"wrong conversion"
<<
std
::
endl
;
++
ret
;
}
b
=
3
;
if
(
b
.
touint
()
!=
3
)
{
std
::
cerr
<<
"wrong conversion"
<<
std
::
endl
;
++
ret
;
}
c
=
a
/
b
;
if
(
c
.
touint
()
!=
100
/
3
)
{
std
::
cerr
<<
"wrong conversion"
<<
std
::
endl
;
++
ret
;
}
std
::
cout
<<
a
<<
"/"
<<
b
<<
"="
<<
c
<<
std
::
endl
;
try
{
...
...
@@ -74,13 +57,14 @@ int main()
b
=
0
;
c
=
a
/
1
;
std
::
cout
<<
a1
<<
"/"
<<
b1
<<
"="
<<
c1
<<
std
::
endl
;
return
ret
;
a
=
1000000
;
std
::
cout
<<
a
.
todouble
()
<<
std
::
endl
;
std
::
cout
<<
a
.
touint
()
<<
std
::
endl
;
b
=
a
;
a
=
a
*
b
*
b
;
std
::
cout
<<
a
.
todouble
()
<<
std
::
endl
;
}
catch
(
Dune
::
MathError
e
)
{
std
::
cout
<<
e
<<
std
::
endl
;
return
1
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment