View previous topic :: View next topic |
Author |
Message |
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Sat Nov 25, 2006 3:05 am Post subject: Little woes with Atoi and exponents |
|
|
Apparently mango.convert.Atoi doesn't handle exponents in Ints. I didn't realize this, until I noticed some values weren't coming out quite right in CashewJSON. (Atoi doesn't complain about them, it just doesn't understand them. Silently.) Basically, given the pattern nE+x the result is always (n*10)+14. So for 1e+3 I get 24, or for 3e-1 I get 44.
I'm sure its a side-effect of Hexadecimal support, and for an easy workaround I'm justing Double.parse() instead. However, it would be nice of Integer/Atoi exposed some way of parsing Base10 values with an exponent.
Or at least complained a little bit about the [+|-] in the middle of it. _________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Sun Nov 26, 2006 4:27 am Post subject: |
|
|
hmmm ... yeah. Atoi was never intended to parse such things. Given that it is built to read from an arbitrary stream, there's really not much it can do when seeing non-digit characters following a set of digits -- it simply stops reading. If it were designed to parse an entire string, then it could report an error instead?
I'm not quite sure what to do about this, Chris, but will give it some thought. Perhaps the right thing to do is support integer exponents, or make it optional? |
|
Back to top |
|
|
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Sun Nov 26, 2006 2:04 pm Post subject: |
|
|
I did have one thought: if given a specific radix, 10 in this case, then it ought to complain about hex digits, but if it comes across an [Ee] it checks for [+-] before complaining, going into an exponent mode if found.
Should probably support Base16 exponents as well, using a [Pp][+-].
...or make a seperate method of Integer/Atoi that knows what to do with exponents. That would be perfectly fine for my purpose at least. _________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
sean
Joined: 24 Jun 2004 Posts: 609 Location: Bay Area, CA
|
Posted: Sun Nov 26, 2006 7:20 pm Post subject: |
|
|
Ideally, I think string conversion routines should support the literal syntax of the underlying language. This would mean exponents for real numbers, octal and hex, etc. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|