Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
149e9ea2
Commit
149e9ea2
authored
Jun 03, 1991
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added dnewlongobject(), function to convert double to long int.
parent
ad40531a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
0 deletions
+39
-0
Objects/longobject.c
Objects/longobject.c
+39
-0
No files found.
Objects/longobject.c
View file @
149e9ea2
...
...
@@ -28,8 +28,14 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "allobjects.h"
#include "longintrepr.h"
#include <math.h>
#include <assert.h>
/* Forward: */
extern
object
*
long_mul
PROTO
((
longobject
*
,
object
*
));
extern
object
*
long_add
PROTO
((
longobject
*
,
object
*
));
extern
object
*
long_neg
PROTO
((
longobject
*
));
static
int
ticker
;
/* XXX Could be shared with ceval? */
#define INTRCHECK(block) \
...
...
@@ -87,6 +93,39 @@ newlongobject(ival)
return
(
object
*
)
v
;
}
/* Create a new long int object from a C double */
object
*
dnewlongobject
(
dval
)
double
dval
;
{
longobject
*
v
;
double
frac
;
int
i
,
ndig
,
expo
,
neg
;
neg
=
0
;
if
(
dval
<
0
.
0
)
{
neg
=
1
;
dval
=
-
dval
;
}
frac
=
frexp
(
dval
,
&
expo
);
/* dval = frac*2**expo; 0.0 <= frac < 1.0 */
if
(
expo
<=
0
)
return
newlongobject
(
0L
);
ndig
=
(
expo
-
1
)
/
SHIFT
+
1
;
/* Number of 'digits' in result */
v
=
alloclongobject
(
ndig
);
if
(
v
==
NULL
)
return
NULL
;
frac
=
ldexp
(
frac
,
(
expo
-
1
)
%
SHIFT
+
1
);
for
(
i
=
ndig
;
--
i
>=
0
;
)
{
long
bits
=
(
long
)
frac
;
v
->
ob_digit
[
i
]
=
bits
;
frac
=
frac
-
(
double
)
bits
;
frac
=
ldexp
(
frac
,
SHIFT
);
}
if
(
neg
)
v
->
ob_size
=
-
v
->
ob_size
;
return
(
object
*
)
v
;
}
/* Get a C long int from a long int object.
Returns -1 and sets an error condition if overflow occurs. */
...
...
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