You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/12/12 09:14:16 UTC
[GitHub] [nuttx] flyingfish89 opened a new pull request, #7850: Add function for math
flyingfish89 opened a new pull request, #7850:
URL: https://github.com/apache/nuttx/pull/7850
## Summary
function:
scalbnf:get a float number of x*2^n
The implementation of the function borrows from musl
## Impact
## Testing
float number1 = scalbnf(2, 10);
printf("%f\n", number1);
number1 = scalbnl(3, 100000);
printf("%f\n", number1);
number = scalbnl(4, 100);
printf("%f\n", number1);
number = scalbnl(5, 1000);
printf("%f\n", number1);
number = scalbnl(12, -10000000);
printf("%f\n", number1);
number = scalbnl(22, 1090000);
printf("%f\n", number1);
number = scalbnl(2075, 10867564);
printf("%f\n", number1);
number = scalbnl(265, -108766);
printf("%f\n", number1);
number = scalbnl(22, -1320);
printf("%f\n", number1);
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7850: Add function for math
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7850:
URL: https://github.com/apache/nuttx/pull/7850#discussion_r1053113761
##########
libs/libc/math/lib_scalbnl.c:
##########
@@ -0,0 +1,45 @@
+/****************************************************************************
+ * libs/libc/math/lib_scalbnl.c
+ * get a long double number of x*2^n
+ *
+ * This file is copy from musl libc
+ * musl is an implementation of the C standard library built on top of the
+ * Linux system call API, including interfaces defined in the base language
+ * standard, POSIX, and widely agreed-upon extensions.
+ * musl is lightweight, fast, simple, free, and strives to be correct in
+ * the sense of standards-conformance and safety.
+ *
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <math.h>
+#include <stdint.h>
+
+/****************************************************************************
+ * Pre-processor definitions
+ ****************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: scalbnl
+ *
+ * Description:
+ * get a long double number of x*2^n
+ *
+ ****************************************************************************/
+
+long double scalbnl(long double x, int n)
+{
+ return scalbn(x, n);
Review Comment:
it's different from musl implementation
##########
libs/libc/math/Make.defs:
##########
@@ -29,6 +29,8 @@ CSRCS += lib_powf.c lib_sinf.c lib_sinhf.c lib_sqrtf.c lib_tanf.c
CSRCS += lib_tanhf.c lib_asinhf.c lib_acoshf.c lib_atanhf.c lib_erff.c
CSRCS += lib_copysignf.c
+CSRCS += lib_scalbnf.c lib_scalbn.c lib_scalbnl.c
Review Comment:
merge to line 30
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] xiaoxiang781216 commented on pull request #7850: Add scalbn[f|l]function to libc math
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #7850:
URL: https://github.com/apache/nuttx/pull/7850#issuecomment-1362816014
@flyingfish89 please add musl copyright to https://github.com/apache/nuttx/blob/master/LICENSE. Please update your commit message carefully in the new patch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7850: Add function for math
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7850:
URL: https://github.com/apache/nuttx/pull/7850#discussion_r1045716329
##########
libs/libc/math/lib_scalbnf.c:
##########
@@ -0,0 +1,76 @@
+/****************************************************************************
+ * libs/libc/math/lib_scalbnf.c
+ * get a double number of x*2^n
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <math.h>
+#include <stdint.h>
+
+#define FLT_MIN 0x1p-126f
Review Comment:
add preprocess section
##########
libs/libc/math/Make.defs:
##########
@@ -28,7 +28,7 @@ CSRCS += lib_ldexpf.c lib_logf.c lib_log10f.c lib_log2f.c lib_modff.c
CSRCS += lib_powf.c lib_sinf.c lib_sinhf.c lib_sqrtf.c lib_tanf.c
CSRCS += lib_tanhf.c lib_asinhf.c lib_acoshf.c lib_atanhf.c lib_erff.c
CSRCS += lib_copysignf.c
-
+CSRCS += lib_scalbnf.c
Review Comment:
merge to previous line
##########
libs/libc/math/lib_scalbnf.c:
##########
@@ -0,0 +1,76 @@
+/****************************************************************************
+ * libs/libc/math/lib_scalbnf.c
+ * get a double number of x*2^n
+ *
+ * This file is a part of NuttX:
Review Comment:
correct the copyright
##########
libs/libc/math/lib_scalbnf.c:
##########
@@ -0,0 +1,76 @@
+/****************************************************************************
+ * libs/libc/math/lib_scalbnf.c
+ * get a double number of x*2^n
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <math.h>
+#include <stdint.h>
+
+#define FLT_MIN 0x1p-126f
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: scalbnf
+ *
+ * Description:
+ * get a float number of x*2^n
+ *
+ ****************************************************************************/
+
+float scalbnf(float x, int n)
Review Comment:
what about scalbn/scalbnl
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] xiaoxiang781216 merged pull request #7850: Add scalbn[f|l]function to libc math
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged PR #7850:
URL: https://github.com/apache/nuttx/pull/7850
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] acassis commented on pull request #7850: Add scalbn[f|l]function to libc math
Posted by GitBox <gi...@apache.org>.
acassis commented on PR #7850:
URL: https://github.com/apache/nuttx/pull/7850#issuecomment-1362811588
@xiaoxiang781216 @flyingfish89 @jerpelea since this file is based on musl and uses BSD license, its should include an entry in the file NOTICE. BTW, the commit msg "1" should be avoided.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] xiaoxiang781216 commented on pull request #7850: Add scalbn[f|l]function to libc math
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #7850:
URL: https://github.com/apache/nuttx/pull/7850#issuecomment-1363589087
Here is the patch to add musl copyright: https://github.com/apache/nuttx/pull/7963
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] xiaoxiang781216 commented on pull request #7850: Add function for math
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #7850:
URL: https://github.com/apache/nuttx/pull/7850#issuecomment-1346327932
please rebase to the last master to fix macOS ci break.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] hartmannathan commented on pull request #7850: Add scalbn[f|l]function to libc math
Posted by GitBox <gi...@apache.org>.
hartmannathan commented on PR #7850:
URL: https://github.com/apache/nuttx/pull/7850#issuecomment-1362898463
@acassis @xiaoxiang781216 @flyingfish89
Unfortunately the merged commit message cannot be changed without messing up everyone's forks/clones (unless someone knows a git trick that I don't know about).
Fortunately the new PR to add copyright/NOTICE can include a new commit message.
For example:
```
libc/math: Add copyright/NOTICE for scalbnf()
The scalbnf() implementation from musl C library was added to NuttX in commit 035656661e2c626e337f0e85ea99d742c9d85c62 (GitHub PR 7850).
```
or something like that.
Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] acassis commented on pull request #7850: Add scalbn[f|l]function to libc math
Posted by GitBox <gi...@apache.org>.
acassis commented on PR #7850:
URL: https://github.com/apache/nuttx/pull/7850#issuecomment-1363206970
Yes, we cannot rewind the git because git could break things for everybody that already synced with the upstream. When we do "git push -f" in our fork it doesn't rewind the upstream branch because the PR area is like a hidden branch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] xiaoxiang781216 commented on pull request #7850: Add scalbn[f|l]function to libc math
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #7850:
URL: https://github.com/apache/nuttx/pull/7850#issuecomment-1362379620
let's ignore temp ci failure(Documentation and macOS).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] xiaoxiang781216 commented on pull request #7850: Add function for math
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #7850:
URL: https://github.com/apache/nuttx/pull/7850#issuecomment-1347666701
Please rebase to the last mater to fix ci broken.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] hartmannathan commented on a diff in pull request #7850: Add function for math
Posted by GitBox <gi...@apache.org>.
hartmannathan commented on code in PR #7850:
URL: https://github.com/apache/nuttx/pull/7850#discussion_r1047669199
##########
libs/libc/math/lib_scalbnf.c:
##########
@@ -0,0 +1,76 @@
+/****************************************************************************
+ * libs/libc/math/lib_scalbnf.c
+ * get a double number of x*2^n
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <math.h>
+#include <stdint.h>
+
+#define FLT_MIN 0x1p-126f
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: scalbnf
+ *
+ * Description:
+ * get a float number of x*2^n
+ *
+ ****************************************************************************/
+
+float scalbnf(float x, int n)
+{
+ union
+ {
+ float f;
+ uint32_t i;
+ }u;
+
+ float_t y = x;
+
+ if (n > 127)
+ {
+ y *= 0x1p127f;
+ n -= 127;
+ if (n > 127)
+ {
+ y *= 0x1p127f;
+ n -= 127;
+ if (n > 127)
+ {
+ n = 127;
+ }
+ }
+ }
+ else if (n < -126)
+ {
+ y *= FLT_MIN * 0x1p24f;
+ n += 126 - 24;
+ if (n < -126)
+ {
+ y *= FLT_MIN * 0x1p24f;
Review Comment:
Same note as above.
##########
libs/libc/math/lib_scalbnf.c:
##########
@@ -0,0 +1,76 @@
+/****************************************************************************
+ * libs/libc/math/lib_scalbnf.c
+ * get a double number of x*2^n
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <math.h>
+#include <stdint.h>
+
+#define FLT_MIN 0x1p-126f
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: scalbnf
+ *
+ * Description:
+ * get a float number of x*2^n
+ *
+ ****************************************************************************/
+
+float scalbnf(float x, int n)
+{
+ union
+ {
+ float f;
+ uint32_t i;
+ }u;
+
+ float_t y = x;
+
+ if (n > 127)
+ {
+ y *= 0x1p127f;
+ n -= 127;
+ if (n > 127)
+ {
+ y *= 0x1p127f;
+ n -= 127;
+ if (n > 127)
+ {
+ n = 127;
+ }
+ }
+ }
+ else if (n < -126)
+ {
+ y *= FLT_MIN * 0x1p24f;
Review Comment:
Note that if the above suggestion is not committed, this reads as:
y *= 0x1p - (126f * 0x1p24f);
but if the above suggestion is committed, this reads as:
y *= (0x1p - 126f) * 0x1p24f;
tl;dr: Committing the above suggestion will change the outcome here. Is there a mistake somewhere?
##########
libs/libc/math/lib_scalbnf.c:
##########
@@ -0,0 +1,76 @@
+/****************************************************************************
+ * libs/libc/math/lib_scalbnf.c
+ * get a double number of x*2^n
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <math.h>
+#include <stdint.h>
+
+#define FLT_MIN 0x1p-126f
Review Comment:
```suggestion
#define FLT_MIN (0x1p-126f)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org