Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
a874a0ab
Commit
a874a0ab
authored
Jan 04, 2014
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed a bug in the bigint object that caused division to sometimes produce
incorrect results.
parent
f0d01c44
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
23 deletions
+24
-23
bigint_kernel_1.cpp
dlib/bigint/bigint_kernel_1.cpp
+7
-11
bigint_kernel_2.cpp
dlib/bigint/bigint_kernel_2.cpp
+8
-12
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
++
r
;
}
// if we are using one less digit
if
(
*
(
r
-
1
)
==
0
)
{
if
(
lhs
->
digits_used
!=
1
)
result
->
digits_used
=
lhs
->
digits_used
-
1
;
else
result
->
digits_used
=
1
;
}
else
result
->
digits_used
=
lhs
->
digits_used
;
// adjust the number of digits used appropriately
--
r
;
while
(
*
r
==
0
&&
result
->
digits_used
>
1
)
{
result
->
digits_used
=
lhs
->
digits_used
;
--
r
;
--
result
->
digits_used
;
}
}
...
...
@@ -1344,7 +1340,7 @@ namespace dlib
// shift rhs left until it is one shift away from being larger than lhs and
// put the number of left shifts necessary into shifts
uint32
shifts
;
shifts
=
(
lhs
->
digits_used
-
rhs
->
digits_used
)
*
8
;
shifts
=
(
lhs
->
digits_used
-
rhs
->
digits_used
)
*
16
;
shift_left
(
rhs
,
&
temp
,
shifts
);
...
...
dlib/bigint/bigint_kernel_2.cpp
View file @
a874a0ab
...
...
@@ -1285,17 +1285,13 @@ namespace dlib
++
r
;
}
// if we are using one less digit
if
(
*
(
r
-
1
)
==
0
)
{
if
(
lhs
->
digits_used
!=
1
)
result
->
digits_used
=
lhs
->
digits_used
-
1
;
else
result
->
digits_used
=
1
;
}
else
result
->
digits_used
=
lhs
->
digits_used
;
// adjust the number of digits used appropriately
--
r
;
while
(
*
r
==
0
&&
result
->
digits_used
>
1
)
{
result
->
digits_used
=
lhs
->
digits_used
;
--
r
;
--
result
->
digits_used
;
}
}
...
...
@@ -1345,7 +1341,7 @@ namespace dlib
// shift rhs left until it is one shift away from being larger than lhs and
// put the number of left shifts necessary into shifts
uint32
shifts
;
shifts
=
(
lhs
->
digits_used
-
rhs
->
digits_used
)
*
8
;
shifts
=
(
lhs
->
digits_used
-
rhs
->
digits_used
)
*
16
;
shift_left
(
rhs
,
&
temp
,
shifts
);
...
...
@@ -1523,7 +1519,7 @@ namespace dlib
// that should happen.
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
// the same time.
uint64
carry
=
0
;
...
...
dlib/test/bigint.cpp
View file @
a874a0ab
...
...
@@ -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