qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v1 1/9] cutils: add qemu_strtod() and qemu_strto


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v1 1/9] cutils: add qemu_strtod() and qemu_strtod_finite()
Date: Thu, 15 Nov 2018 12:02:41 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0

On 11/15/18 11:25 AM, David Hildenbrand wrote:

Also, just overflow.  Floating-point underflow is when a computation's
mathematical result is too close to zero to be represented without
extraordinary rounding error.


works like qemu_strtoul().  I'd prefer longhand for qemu_strtod().  It
costs us a few lines, but it results in a clearer contract.

/**
  * Convert string @nptr to a double.
   *
  * This is a wrapper around strtod() that is harder to misuse.
  * Semantics of @nptr and @endptr match strtod() with differences
  * noted below.
  *
  * @nptr may be null, and no conversion is performed then.
  *
  * If no conversion is performed, store @nptr in address@hidden and return
  * -EINVAL.
  *
  * If @endptr is null, and the string isn't fully converted, return
  * -EINVAL.  This is the case when the pointer that would be stored in
  * a non-null @endptr points to a character other than '\0'.
  *
  * If the conversion overflows @result, store +/-HUGE_VAL, depending on
  * the sign, in @result and return -ERANGE.

Fails to mention underflow. Maybe add:

If the conversion underflows, store +/-0.0 in @result, depending on the sign, and return -ERANGE.

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]