libc/math: Fix for wrong ouput in modf() API
authorLokesh B V <lokesh.bv@partner.samsung.com>
Wed, 19 Jul 2017 14:52:14 +0000 (20:22 +0530)
committerLokesh B V <lokesh.bv@partner.samsung.com>
Wed, 19 Jul 2017 14:58:03 +0000 (20:28 +0530)
The sign of integral part given by the modf() should be same as sign of input.
But for inputs between 0 and 1, the sign of integral part was not same as sign of input.

Signed-off-by: Lokesh B V <lokesh.bv@partner.samsung.com>
lib/libc/math/lib_modf.c
lib/libc/math/lib_modff.c
lib/libc/math/lib_modfl.c

index 79362dc..e960e5f 100644 (file)
@@ -1,6 +1,6 @@
 /****************************************************************************
  *
- * Copyright 2016 Samsung Electronics All Rights Reserved.
+ * Copyright 2016-2017 Samsung Electronics All Rights Reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -60,7 +60,7 @@ double modf(double x, double *iptr)
                *iptr = x;
                return 0.0;
        } else if (fabs(x) < 1.0) {
-               *iptr = 0.0;
+               *iptr = (x * 0.0);
                return x;
        } else {
                *iptr = (double)(int64_t)x;
index f424496..9846c18 100644 (file)
@@ -1,6 +1,6 @@
 /****************************************************************************
  *
- * Copyright 2016 Samsung Electronics All Rights Reserved.
+ * Copyright 2016-2017 Samsung Electronics All Rights Reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -58,7 +58,7 @@ float modff(float x, float *iptr)
                *iptr = x;
                return 0.0;
        } else if (fabs(x) < 1.0) {
-               *iptr = 0.0;
+               *iptr = (x * 0.0);
                return x;
        } else {
                *iptr = (float)(int)x;
index 5340c81..d5dc03b 100644 (file)
@@ -1,6 +1,6 @@
 /****************************************************************************
  *
- * Copyright 2016 Samsung Electronics All Rights Reserved.
+ * Copyright 2016-2017 Samsung Electronics All Rights Reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -62,7 +62,7 @@ long double modfl(long double x, long double *iptr)
                *iptr = x;
                return 0.0;
        } else if (fabs(x) < 1.0) {
-               *iptr = 0.0;
+               *iptr = (x * 0.0);
                return x;
        } else {
                *iptr = (long double)(int64_t)x;