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
ruanhaishen
redis
Commits
fe244589
Commit
fe244589
authored
May 13, 2010
by
antirez
Browse files
Yet another version of the double saving code, with comments explaining what's happening there
parent
5107436c
Changes
1
Hide whitespace changes
Inline
Side-by-side
redis.c
View file @
fe244589
...
@@ -3513,7 +3513,18 @@ static int rdbSaveDoubleValue(FILE *fp, double val) {
...
@@ -3513,7 +3513,18 @@ static int rdbSaveDoubleValue(FILE *fp, double val) {
len
=
1
;
len
=
1
;
buf
[
0
]
=
(
val
<
0
)
?
255
:
254
;
buf
[
0
]
=
(
val
<
0
)
?
255
:
254
;
}
else
{
}
else
{
if
(
val
>
LLONG_MAX
&&
val
<
LLONG_MIN
&&
val
==
((
long
long
)
val
))
/* Check if the float is in a safe range to be casted into a
* long long. We are assuming that long long is 64 bit here.
* Also we are assuming that there are no implementations around where
* double has precision < 52 bit.
*
* Under this assumptions we test if a double is inside an interval
* where casting to long long is safe. Then using two castings we
* make sure the decimal part is zero. If all this is true we use
* integer printing function that is much faster. */
double
min
=
-
4503599627370495
;
double
max
=
4503599627370496
;
if
(
val
>
min
&&
val
<
max
&&
val
==
((
double
)((
long
long
)
val
)))
ll2string
((
char
*
)
buf
+
1
,
sizeof
(
buf
),(
long
long
)
val
);
ll2string
((
char
*
)
buf
+
1
,
sizeof
(
buf
),(
long
long
)
val
);
else
else
snprintf
((
char
*
)
buf
+
1
,
sizeof
(
buf
)
-
1
,
"%.17g"
,
val
);
snprintf
((
char
*
)
buf
+
1
,
sizeof
(
buf
)
-
1
,
"%.17g"
,
val
);
...
...
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