This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: [Ask for help]: Met a problem with strtof
- From: Wang Weidong <wangweidong1 at huawei dot com>
- To: <ms_brown at sbcglobal dot net>
- Cc: <libc-help at sourceware dot org>, <drepper at gnu dot org>
- Date: Thu, 24 Apr 2014 09:30:02 +0800
- Subject: Re: [Ask for help]: Met a problem with strtof
- Authentication-results: sourceware.org; auth=none
- References: <53566C6A dot 4050804 at huawei dot com> <5358058F dot 9010806 at sbcglobal dot net>
On 2014/4/24 2:25, Mark Brown wrote:
> Hello-
>
> While I am not a true floating point expert, it would help to know:
>
> What headers you are including (for example, are you using <stdlib.h>)?
> What compile options are you using (for example, on the older gcc, are
> you using -std=c99 )?
>
>
Thanks for your reply.
The headers which I included are those:
#include <stdio.h>
#include <stdlib.h>
#include <fenv.h>
I use `gcc -std=c99 -lm test.c -o test` to compile it.
then do it `./test`
Regards
Wang
>
> On 04/22/2014 08:19 AM, Wang Weidong wrote:
>> Hi,
>>
>> I test the code below :
>> -------------------------------------------------------------
>> int main() {
>>
>> char *str1="-0x1.4EF009P-16";
>> char *str2="-0x1.744513P-55";
>> char *str3="+0x1.1C7509P-19";
>> float temp;
>>
>> fesetround(FE_UPWARD);
>>
>> temp = strtof(str1, NULL);
>> printf(" %s -> %a\n", str1, temp);
>>
>> fesetround(FE_DOWNWARD);
>>
>> temp = strtof(str2, NULL);
>> printf("%s -> %a\n", str2, temp);
>> temp = strtof(str3, NULL);
>> printf("%s -> %a\n", str3, temp);
>> return 0;
>> }
>>
>> -------------------------------------------------------------
>>
>> I met a problem as below:
>> On SUSE-SP1 x86_64 with glibc-2.11-3 and gcc-4.3.2
>> I got the result:
>>
>> -0x1.4EF009P-16 -> -0x1.4ef00ap-16
>> -0x1.744513P-55 -> -0x1.744514p-55
>> +0x1.1C7509P-19 -> 0x1.1c750ap-19
>>
>> while On Fedora x86_64 with glibc-2.17-19 and gcc-4.8.2
>> I got the result:
>>
>> -0x1.4EF009P-16 -> -0x1.4ef008p-16
>> -0x1.744513P-55 -> -0x1.744512p-55
>> +0x1.1C7509P-19 -> 0x1.1c7508p-19
>>
>> All the fesetround setted success.
>> Can someone tell me which is right and why?
>