[v2 5/6] msvcirt: Implement istream::operator>> for floats.

Piotr Caban piotr.caban at gmail.com
Tue Aug 2 08:52:24 CDT 2016


On 08/02/16 13:37, Iván Matellanes wrote:
> +static istream* istream_internal_read_float(istream *this, void *p, int size)
> +{
> +    /* size: 0 => float, 1 => double, 2 => long double */
> +    const int max_chars[3] = {20, 28, 32}; /* character count is limited on Windows */
> +    char buffer[32];
> +    double d;
> +
> +    TRACE("(%p %p %d)\n", this, p, size);
> +
> +    if (istream_ipfx(this, 0)) {
> +        if (istream_getdouble(this, buffer, max_chars[size]) > 0) {
> +            d = strtod(buffer, NULL);
> +            if (size == 0) {
> +                /* check whether the value fits in the output var */
> +                if (d > FLT_MAX)
> +                    d = FLT_MAX;
> +                else if (d < -FLT_MAX)
> +                    d = -FLT_MAX;
> +                else if (d > 0 && d < FLT_MIN)
> +                    d = FLT_MIN;
> +                else if (d < 0 && d > -FLT_MIN)
> +                    d = -FLT_MIN;
> +                *((float*) p) = d;

I think that this helper will be nicer if it has following prototype:
static double istream_internal_read_float(istream *this, int max_chars);
where max_chars is set to 20, 28 or 32 depending if float, double or 
LDOUBLE needs to be read. With FLT_MIN/FLT_MAX checks moved to 
operator>>(float) implementation.

Thanks,
Piotr




More information about the wine-devel mailing list