Author Topic: Expected 0.011111 but got scientific notation  (Read 3682 times)

0 Members and 1 Guest are viewing this topic.

Offline Craz1000

  • Forum Regular
  • Posts: 111
  • I'm OK
    • View Profile
    • Craz1000.net
Expected 0.011111 but got scientific notation
« 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

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Expected 0.011111 but got scientific notation
« Reply #1 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....
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline Craz1000

  • Forum Regular
  • Posts: 111
  • I'm OK
    • View Profile
    • Craz1000.net
Re: Expected 0.011111 but got scientific notation
« Reply #2 on: March 03, 2019, 12:10:12 pm »
Ah ok
« Last Edit: March 03, 2019, 12:11:34 pm by Craz1000 »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Expected 0.011111 but got scientific notation
« Reply #3 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Expected 0.011111 but got scientific notation
« Reply #4 on: March 04, 2019, 06:09:31 am »
The QB64 wiki is always a useful resource.

http://qb64.org/wiki/Scientific_notation

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Expected 0.011111 but got scientific notation
« Reply #5 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!

Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: Expected 0.011111 but got scientific notation
« Reply #6 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
« Last Edit: March 04, 2019, 01:06:41 pm by jack »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Expected 0.011111 but got scientific notation
« Reply #7 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Bert22306

  • Forum Regular
  • Posts: 206
    • View Profile
Re: Expected 0.011111 but got scientific notation
« Reply #8 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?
« Last Edit: March 04, 2019, 04:26:45 pm by Bert22306 »