Comments (3)
For information, it seems also to have the same problem with the original, https://github.com/mattn/strtod.
Adding values in 0.1
intervals from 0.2
to 0.9
and reporting only failures, the results are shown below.
% cc strtod.c -lm && ./a.out
CASE: .3
ERR: .3, No error: 0
E1 0.300000, 0.3, , 0
E2 0.300000, 0.3, , 0
different value
CASE: .6
ERR: .6, No error: 0
E1 0.600000, 0.6, , 0
E2 0.600000, 0.6, , 0
different value
CASE: .7
ERR: .7, No error: 0
E1 0.700000, 0.7, , 0
E2 0.700000, 0.7, , 0
different value
CASE: 2.2250738585072010e-308
ERR: 2.2250738585072010e-308, Result too large
E1 0.000000, 0, , 34
E2 0.000000, 2.22507e-308, , 34
different value
CASE: 2.2250738585072011e-308
ERR: 2.2250738585072011e-308, Result too large
E1 0.000000, 0, , 34
E2 0.000000, 2.22507e-308, , 34
different value
patch for test of strtod.c
diff --git a/strtod.c b/strtod.c
index bd5378b..42bb574 100644
--- a/strtod.c
+++ b/strtod.c
@@ -148,8 +148,6 @@ test(char* str)
char *e1, *e2;
int x1, x2;
- printf("CASE: %s\n", str);
-
errno = 0;
e1 = NULL;
d1 = vim_strtod(str, &e1);
@@ -161,22 +159,29 @@ test(char* str)
x2 = errno;
if (d1 != d2 || e1 != e2 || x1 != x2) {
+ printf("CASE: %s\n", str);
printf(" ERR: %s, %s\n", str, strerror(errno));
printf(" E1 %f, %g, %s, %d\n", d1, d1, e1 ? e1 : "", x1);
printf(" E2 %f, %g, %s, %d\n", d2, d2, e2 ? e2 : "", x2);
if (d1 != d2) puts("different value");
if (e1 != e2) puts("different end position");
if (x1 != x2) puts("different errno");
- } else {
- printf(" SUCCESS [%f][%s]: %s\n", d1, e1 ? e1 : "", strerror(errno));
+ printf("\n");
}
- printf("\n");
}
int
main()
{
test(".1");
+ test(".2");
+ test(".3");
+ test(".4");
+ test(".5");
+ test(".6");
+ test(".7");
+ test(".8");
+ test(".9");
test(" .");
test(" 1.2e3");
test(" +1.2e3");
from mruby.
For several reasons, I recommend mruby-marshal
to use mrb_read_float()
instead of strtod()
.
strtod()
uses locale which is fragile (for example we need to use0,3
not0.3
for some locale)- it is very hard to implement bit-to-bit equality with independent string-to-float functions
For the same reason, I recommend to use mrb_float_to_str()
instead of printf()
.
from mruby.
Understood. Thank you very much.
I tried that too, but it's not possible.
I think it makes sense to write it in doc/limitations.md
as it is now, so I'll update that one.
from mruby.
Related Issues (20)
- Verson 3.3.0: time.h declares mrb_time_at. Function changed to time_at (no mrb_) HOT 1
- Unary minus seems broken HOT 1
- Build option to build a shared library and link it with the resulting binaries HOT 2
- Differentiate between `lib` and `lib64` in the build settings. HOT 3
- Wrong number of characters in broken UTF-8 string HOT 1
- Any way to do a microruby ala microperl? HOT 7
- https://mruby.org/docs/api/ is missing Object, possibly others HOT 1
- Unable to define `==` for objects when using `Array#delete` HOT 5
- When `MRB_UTF8_STRING` is enabled, giving byte characters for `String#index` and `String#split` gives wrong results HOT 3
- Parse error with required kwargs and omitted parens
- `NODE_ZSUPER` from deeply nested blocks will result in a truncated digits for block index in `OP_ARGARY` HOT 1
- `NODE_SUPER` / `NODE_ZSUPER` on the top level passes the wrong block index to `gen_blkmove()` which generates `OP_GETUPVAR`
- MSVC: can't use `malloc()` in `string.c` with `WIN32_LEAN_AND_MEAN` HOT 3
- build with build_config.rb w/mruby extensions succeeds but doesn't create SciTE binary HOT 1
- mrb_fixnum returns wrong value if integer is large HOT 1
- Segmentation fault in function get_file in debug.c HOT 3
- Mirror of prettier package for pre-commit is now archived HOT 1
- Assigning to a block variable changes the actual block (thus affecting `block_given?` and `yield`) HOT 3
- `foo :bar {}` is legal in mruby?
- method call faile on arm v5 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mruby.