Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
260fd8a4
Commit
260fd8a4
authored
Sep 24, 2007
by
Karl Relton
Committed by
Alexandre Julliard
Sep 25, 2007
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
msvcrt: New implementation of fcvt.
parent
6f9bcd59
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
149 additions
and
35 deletions
+149
-35
math.c
dlls/msvcrt/math.c
+71
-6
printf.c
dlls/msvcrt/tests/printf.c
+78
-29
No files found.
dlls/msvcrt/math.c
View file @
260fd8a4
...
...
@@ -873,16 +873,81 @@ char * CDECL _ecvt( double number, int ndigits, int *decpt, int *sign )
char
*
CDECL
_fcvt
(
double
number
,
int
ndigits
,
int
*
decpt
,
int
*
sign
)
{
thread_data_t
*
data
=
msvcrt_get_thread_data
();
char
*
dec
;
int
stop
,
dec1
,
dec2
;
char
*
ptr1
,
*
ptr2
,
*
first
;
char
buf
[
80
];
/* ought to be enough */
if
(
!
data
->
efcvt_buffer
)
data
->
efcvt_buffer
=
MSVCRT_malloc
(
80
);
/* ought to be enough */
snprintf
(
data
->
efcvt_buffer
,
80
,
"%.*e"
,
ndigits
,
number
);
*
sign
=
(
number
<
0
);
dec
=
strchr
(
data
->
efcvt_buffer
,
'.'
);
*
decpt
=
(
dec
)
?
dec
-
data
->
efcvt_buffer
:
-
1
;
return
data
->
efcvt_buffer
;
if
(
number
<
0
)
{
*
sign
=
1
;
number
=
-
number
;
}
else
*
sign
=
0
;
snprintf
(
buf
,
80
,
"%.*f"
,
ndigits
<
0
?
0
:
ndigits
,
number
);
ptr1
=
buf
;
ptr2
=
data
->
efcvt_buffer
;
first
=
NULL
;
dec1
=
0
;
dec2
=
0
;
/* For numbers below the requested resolution, work out where
the decimal point will be rather than finding it in the string */
if
(
number
<
1
.
0
&&
number
>
0
.
0
)
{
dec2
=
log10
(
number
+
1e-10
);
if
(
-
dec2
<=
ndigits
)
dec2
=
0
;
}
/* If requested digits is zero or less, we will need to truncate
* the returned string */
if
(
ndigits
<
1
)
{
stop
=
strlen
(
buf
)
+
ndigits
;
}
else
{
stop
=
strlen
(
buf
);
}
while
(
*
ptr1
==
'0'
)
ptr1
++
;
/* Skip leading zeroes */
while
(
*
ptr1
!=
'\0'
&&
*
ptr1
!=
'.'
)
{
if
(
!
first
)
first
=
ptr2
;
if
((
ptr1
-
buf
)
<
stop
)
{
*
ptr2
++
=
*
ptr1
++
;
}
else
{
ptr1
++
;
}
dec1
++
;
}
if
(
ndigits
>
0
)
{
ptr1
++
;
if
(
!
first
)
{
while
(
*
ptr1
==
'0'
)
{
/* Process leading zeroes */
*
ptr2
++
=
*
ptr1
++
;
dec1
--
;
}
}
while
(
*
ptr1
!=
'\0'
)
{
if
(
!
first
)
first
=
ptr2
;
*
ptr2
++
=
*
ptr1
++
;
}
}
*
ptr2
=
'\0'
;
/* We never found a non-zero digit, then our number is either
* smaller than the requested precision, or 0.0 */
if
(
!
first
)
{
if
(
number
>
0
.
0
)
{
first
=
ptr2
;
}
else
{
first
=
data
->
efcvt_buffer
;
dec1
=
0
;
}
}
*
decpt
=
dec2
?
dec2
:
dec1
;
return
first
;
}
/***********************************************************************
...
...
dlls/msvcrt/tests/printf.c
View file @
260fd8a4
...
...
@@ -552,47 +552,96 @@ static void test_fcvt(void)
char
*
str
;
int
dec
=
100
,
sign
=
100
;
/* Numbers less than 1.0 with different precisions */
str
=
_fcvt
(
0
.
0001
,
1
,
&
dec
,
&
sign
);
todo_wine
{
ok
(
0
==
strcmp
(
str
,
""
),
"bad return
\n
"
);
ok
(
-
3
==
dec
,
"dec wrong
\n
"
);
}
ok
(
0
==
sign
,
"dec wrong
\n
"
);
ok
(
0
==
strcmp
(
str
,
""
),
"bad return '%s'
\n
"
,
str
);
ok
(
-
3
==
dec
,
"dec wrong %d
\n
"
,
dec
);
ok
(
0
==
sign
,
"sign wrong
\n
"
);
str
=
_fcvt
(
0
.
0001
,
-
10
,
&
dec
,
&
sign
);
todo_wine
{
ok
(
0
==
strcmp
(
str
,
""
),
"bad return
\n
"
);
ok
(
-
3
==
dec
,
"dec wrong
\n
"
);
}
ok
(
0
==
sign
,
"dec wrong
\n
"
);
ok
(
0
==
strcmp
(
str
,
""
),
"bad return '%s'
\n
"
,
str
);
ok
(
-
3
==
dec
,
"dec wrong %d
\n
"
,
dec
);
ok
(
0
==
sign
,
"sign wrong
\n
"
);
str
=
_fcvt
(
0
.
0001
,
10
,
&
dec
,
&
sign
);
todo_wine
{
ok
(
0
==
strcmp
(
str
,
"1000000"
),
"bad return
\n
"
);
ok
(
-
3
==
dec
,
"dec wrong
\n
"
);
}
ok
(
0
==
sign
,
"dec wrong
\n
"
);
ok
(
0
==
strcmp
(
str
,
"1000000"
),
"bad return '%s'
\n
"
,
str
);
ok
(
-
3
==
dec
,
"dec wrong %d
\n
"
,
dec
);
ok
(
0
==
sign
,
"sign wrong
\n
"
);
/* Basic sign test */
str
=
_fcvt
(
-
111
.
0001
,
5
,
&
dec
,
&
sign
);
todo_wine
{
ok
(
0
==
strcmp
(
str
,
"11100010"
),
"bad return
\n
"
);
ok
(
3
==
dec
,
"dec wrong
\n
"
);
}
ok
(
1
==
sign
,
"dec wrong
\n
"
);
ok
(
0
==
strcmp
(
str
,
"11100010"
),
"bad return '%s'
\n
"
,
str
);
ok
(
3
==
dec
,
"dec wrong %d
\n
"
,
dec
);
ok
(
1
==
sign
,
"sign wrong
\n
"
);
str
=
_fcvt
(
111
.
0001
,
5
,
&
dec
,
&
sign
);
todo_wine
{
ok
(
0
==
strcmp
(
str
,
"11100010"
),
"bad return
\n
"
);
ok
(
0
==
strcmp
(
str
,
"11100010"
),
"bad return '%s'
\n
"
,
str
);
ok
(
3
==
dec
,
"dec wrong
\n
"
);
}
ok
(
0
==
sign
,
"dec wrong
\n
"
);
ok
(
0
==
sign
,
"sign wrong
\n
"
);
/* 0.0 with different precisions */
str
=
_fcvt
(
0
.
0
,
5
,
&
dec
,
&
sign
);
todo_wine
{
ok
(
0
==
strcmp
(
str
,
"00000"
),
"bad return
\n
"
);
ok
(
0
==
dec
,
"dec wrong
\n
"
);
}
ok
(
0
==
sign
,
"dec wrong
\n
"
);
ok
(
0
==
strcmp
(
str
,
"00000"
),
"bad return '%s'
\n
"
,
str
);
ok
(
0
==
dec
,
"dec wrong %d
\n
"
,
dec
);
ok
(
0
==
sign
,
"sign wrong
\n
"
);
str
=
_fcvt
(
0
.
0
,
0
,
&
dec
,
&
sign
);
ok
(
0
==
strcmp
(
str
,
""
),
"bad return '%s'
\n
"
,
str
);
ok
(
0
==
dec
,
"dec wrong %d
\n
"
,
dec
);
ok
(
0
==
sign
,
"sign wrong
\n
"
);
str
=
_fcvt
(
0
.
0
,
-
1
,
&
dec
,
&
sign
);
ok
(
0
==
strcmp
(
str
,
""
),
"bad return '%s'
\n
"
,
str
);
ok
(
0
==
dec
,
"dec wrong %d
\n
"
,
dec
);
ok
(
0
==
sign
,
"sign wrong
\n
"
);
/* Numbers > 1.0 with 0 or -ve precision */
str
=
_fcvt
(
-
123
.
0001
,
0
,
&
dec
,
&
sign
);
ok
(
0
==
strcmp
(
str
,
"123"
),
"bad return '%s'
\n
"
,
str
);
ok
(
3
==
dec
,
"dec wrong %d
\n
"
,
dec
);
ok
(
1
==
sign
,
"sign wrong
\n
"
);
str
=
_fcvt
(
-
123
.
0001
,
-
1
,
&
dec
,
&
sign
);
ok
(
0
==
strcmp
(
str
,
"12"
),
"bad return '%s'
\n
"
,
str
);
ok
(
3
==
dec
,
"dec wrong %d
\n
"
,
dec
);
ok
(
1
==
sign
,
"sign wrong
\n
"
);
str
=
_fcvt
(
-
123
.
0001
,
-
2
,
&
dec
,
&
sign
);
ok
(
0
==
strcmp
(
str
,
"1"
),
"bad return '%s'
\n
"
,
str
);
ok
(
3
==
dec
,
"dec wrong %d
\n
"
,
dec
);
ok
(
1
==
sign
,
"sign wrong
\n
"
);
str
=
_fcvt
(
-
123
.
0001
,
-
3
,
&
dec
,
&
sign
);
ok
(
0
==
strcmp
(
str
,
""
),
"bad return '%s'
\n
"
,
str
);
ok
(
3
==
dec
,
"dec wrong %d
\n
"
,
dec
);
ok
(
1
==
sign
,
"sign wrong
\n
"
);
/* Numbers > 1.0, but with rounding at the point of precision */
str
=
_fcvt
(
99
.
99
,
1
,
&
dec
,
&
sign
);
ok
(
0
==
strcmp
(
str
,
"1000"
),
"bad return '%s'
\n
"
,
str
);
ok
(
3
==
dec
,
"dec wrong %d
\n
"
,
dec
);
ok
(
0
==
sign
,
"sign wrong
\n
"
);
/* Numbers < 1.0 where rounding occurs at the point of precision */
str
=
_fcvt
(
0
.
00636
,
2
,
&
dec
,
&
sign
);
ok
(
0
==
strcmp
(
str
,
"1"
),
"bad return '%s'
\n
"
,
str
);
ok
(
-
1
==
dec
,
"dec wrong %d
\n
"
,
dec
);
ok
(
0
==
sign
,
"sign wrong
\n
"
);
str
=
_fcvt
(
0
.
00636
,
3
,
&
dec
,
&
sign
);
ok
(
0
==
strcmp
(
str
,
"6"
),
"bad return '%s'
\n
"
,
str
);
ok
(
-
2
==
dec
,
"dec wrong %d
\n
"
,
dec
);
ok
(
0
==
sign
,
"sign wrong
\n
"
);
str
=
_fcvt
(
0
.
09999999996
,
2
,
&
dec
,
&
sign
);
ok
(
0
==
strcmp
(
str
,
"10"
),
"bad return '%s'
\n
"
,
str
);
ok
(
0
==
dec
,
"dec wrong %d
\n
"
,
dec
);
ok
(
0
==
sign
,
"sign wrong
\n
"
);
str
=
_fcvt
(
0
.
6
,
0
,
&
dec
,
&
sign
);
ok
(
0
==
strcmp
(
str
,
"1"
),
"bad return '%s'
\n
"
,
str
);
ok
(
1
==
dec
,
"dec wrong %d
\n
"
,
dec
);
ok
(
0
==
sign
,
"sign wrong
\n
"
);
}
START_TEST
(
printf
)
...
...
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