Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
a874a0ab
Commit
a874a0ab
authored
Jan 04, 2014
by
Davis King
Browse files
Fixed a bug in the bigint object that caused division to sometimes produce
incorrect results.
parent
f0d01c44
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
23 deletions
+24
-23
dlib/bigint/bigint_kernel_1.cpp
dlib/bigint/bigint_kernel_1.cpp
+7
-11
dlib/bigint/bigint_kernel_2.cpp
dlib/bigint/bigint_kernel_2.cpp
+8
-12
dlib/test/bigint.cpp
dlib/test/bigint.cpp
+9
-0
No files found.
dlib/bigint/bigint_kernel_1.cpp
View file @
a874a0ab
...
@@ -1284,17 +1284,13 @@ namespace dlib
...
@@ -1284,17 +1284,13 @@ namespace dlib
++
r
;
++
r
;
}
}
// if we are using one less digit
result
->
digits_used
=
lhs
->
digits_used
;
if
(
*
(
r
-
1
)
==
0
)
// adjust the number of digits used appropriately
{
--
r
;
if
(
lhs
->
digits_used
!=
1
)
while
(
*
r
==
0
&&
result
->
digits_used
>
1
)
result
->
digits_used
=
lhs
->
digits_used
-
1
;
else
result
->
digits_used
=
1
;
}
else
{
{
result
->
digits_used
=
lhs
->
digits_used
;
--
r
;
--
result
->
digits_used
;
}
}
}
}
...
@@ -1344,7 +1340,7 @@ namespace dlib
...
@@ -1344,7 +1340,7 @@ namespace dlib
// shift rhs left until it is one shift away from being larger than lhs and
// shift rhs left until it is one shift away from being larger than lhs and
// put the number of left shifts necessary into shifts
// put the number of left shifts necessary into shifts
uint32
shifts
;
uint32
shifts
;
shifts
=
(
lhs
->
digits_used
-
rhs
->
digits_used
)
*
8
;
shifts
=
(
lhs
->
digits_used
-
rhs
->
digits_used
)
*
16
;
shift_left
(
rhs
,
&
temp
,
shifts
);
shift_left
(
rhs
,
&
temp
,
shifts
);
...
...
dlib/bigint/bigint_kernel_2.cpp
View file @
a874a0ab
...
@@ -1285,17 +1285,13 @@ namespace dlib
...
@@ -1285,17 +1285,13 @@ namespace dlib
++
r
;
++
r
;
}
}
// if we are using one less digit
result
->
digits_used
=
lhs
->
digits_used
;
if
(
*
(
r
-
1
)
==
0
)
// adjust the number of digits used appropriately
{
--
r
;
if
(
lhs
->
digits_used
!=
1
)
while
(
*
r
==
0
&&
result
->
digits_used
>
1
)
result
->
digits_used
=
lhs
->
digits_used
-
1
;
else
result
->
digits_used
=
1
;
}
else
{
{
result
->
digits_used
=
lhs
->
digits_used
;
--
r
;
--
result
->
digits_used
;
}
}
}
}
...
@@ -1345,7 +1341,7 @@ namespace dlib
...
@@ -1345,7 +1341,7 @@ namespace dlib
// shift rhs left until it is one shift away from being larger than lhs and
// shift rhs left until it is one shift away from being larger than lhs and
// put the number of left shifts necessary into shifts
// put the number of left shifts necessary into shifts
uint32
shifts
;
uint32
shifts
;
shifts
=
(
lhs
->
digits_used
-
rhs
->
digits_used
)
*
8
;
shifts
=
(
lhs
->
digits_used
-
rhs
->
digits_used
)
*
16
;
shift_left
(
rhs
,
&
temp
,
shifts
);
shift_left
(
rhs
,
&
temp
,
shifts
);
...
@@ -1523,7 +1519,7 @@ namespace dlib
...
@@ -1523,7 +1519,7 @@ namespace dlib
// that should happen.
// that should happen.
ifft
(
a
,
size
);
ifft
(
a
,
size
);
// loop over the result and prop
i
gate any carries that need to take place.
// loop over the result and prop
a
gate any carries that need to take place.
// We will also be moving the resulting numbers into result->number at
// We will also be moving the resulting numbers into result->number at
// the same time.
// the same time.
uint64
carry
=
0
;
uint64
carry
=
0
;
...
...
dlib/test/bigint.cpp
View file @
a874a0ab
...
@@ -473,6 +473,15 @@ namespace
...
@@ -473,6 +473,15 @@ namespace
a
=
10000
;
a
=
a
*
a
*
a
*
a
;
a
=
a
*
a
;
a
=
a
*
a
;
b
=
2
;
DLIB_TEST
((
a
/
b
)
*
b
==
a
);
a
=
10000
*
5
;
a
=
a
*
a
*
a
*
a
;
a
=
a
*
a
;
a
=
a
*
a
;
b
=
5
;
DLIB_TEST
((
a
/
b
)
*
b
==
a
);
}
}
...
...
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