QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Craz1000 on March 03, 2019, 11:48:52 am

Title: Expected 0.011111 but got scientific notation
Post by: Craz1000 on March 03, 2019, 11:48:52 am
Has anyone else ran into this?
if you divide 1 / 90  you get 1.1111111111D-02

shouldn't it be 0.01111111
Title: Re: Expected 0.011111 but got scientific notation
Post by: Ashish on March 03, 2019, 12:04:02 pm
Has anyone else ran into this?
if you divide 1 / 90  you get 1.1111111111D-02

shouldn't it be 0.01111111
1.1111111111D-02, here D-02 means multiplying 1.1111111111 by 10^(-2)., which is equal to 0.0111111111111....
Title: Re: Expected 0.011111 but got scientific notation
Post by: Craz1000 on March 03, 2019, 12:10:12 pm
Ah ok
Title: Re: Expected 0.011111 but got scientific notation
Post by: Pete on March 03, 2019, 12:56:44 pm
Try the string math project I've been working on for that 1 / 90 example: https://www.qb64.org/forum/index.php?topic=1093.msg103166#msg103166

Don't rely on it though, it's purely in beta and very untested.

@Ashish: Nice job at explaining the scientific notation part, young man.

Pete
Title: Re: Expected 0.011111 but got scientific notation
Post by: Qwerkey on March 04, 2019, 06:09:31 am
The QB64 wiki is always a useful resource.

http://qb64.org/wiki/Scientific_notation (http://qb64.org/wiki/Scientific_notation)
Title: Re: Expected 0.011111 but got scientific notation
Post by: Pete on March 04, 2019, 12:19:55 pm
The scariest part about that page is the example coded by Clippy. He typoed it!

Well, fortunately, my routine can change what his function does, back. :D :D :D

Pete

- Anything Ted can do, I can undo better, I can undo anything better than you!

Title: Re: Expected 0.011111 but got scientific notation
Post by: jack on March 04, 2019, 12:45:51 pm
I agree with Craz1000, the expected output for free format should be  0.01111111111111111, unless he's print using$
while the output of 1.1111111111D-02 is valid, it does not seem to follow popular conventions.
https://stackoverflow.com/questions/38076102/from-when-format-specifier-g-for-double-starts-printing-in-exponential-format
[edit]
Qbasic also prints in exponential format, so I guess it's Qbasic compatibility feature
Title: Re: Expected 0.011111 but got scientific notation
Post by: Pete on March 04, 2019, 01:33:43 pm
These are some of the "feature" headaches I'm trying to iron out for string math. Frankly, I'm considering not keeping it compatible with QB results if those QB results are not consistent with more accepted standards. Too bad I'm not a math guy. 40 years out of college does not do a mind or body good. Now if I can just invent a calculator that subtracts 12 pounds...

Oh, speaking of the Wiki, and thanks to Odin for fixing the typo I discovered, I also noted with Ted's example that you cannot use a number past D308. That, to me means he didn't make it pure string. It must be being hindered by the DOUBLE variable limits. I will probably make my own to convert back, for that reason.

Pete
Title: Re: Expected 0.011111 but got scientific notation
Post by: Bert22306 on March 04, 2019, 04:22:31 pm
Wait, guys, I'm confused about the confusion. I agree that Ashish explained scientific notation well, but I'm confused as to what QB64 might be doing "wrong."

In fact, like QB also seemed to do, scientific notation is created by QB64 only after a certain  number of digits. It makes some sense, to me, to go to scientific notation beyond a certain point. Looks like 16 digits is the limit. So:

PRINT .0111111111111111

will print just like that. But add one more digit, and

PRINT .01111111111111111

will print as

 1.111111111111111D-02

Same the other way around. If you input a number in scientific notation, but the number is not "long enough," QB64 will print it back without scientific notation.

Not sure why this isn't legit in every way? Or is there some sort of unwritten rule in other programming languages, as to when scientific notation becomes essential?