Author Topic: I don't often work with numbers, but when I do....  (Read 7669 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
I don't often work with numbers, but when I do....
« on: September 10, 2021, 01:51:30 am »
So I ran across this old rounding routine I made several years ago, which rounds up decimals like .49 to .5, etc. it converts the numeric variable to a string, rounds it, and then returns it as a rounded numeric variable. All well and good, until I came across this input...

.49999999

That should have came out as .5, but rounded up to 1 in my routine. Now my routine does takes anything .5 and up and makes it one. So what I discovered is QB64 does this when it encounters this many digits in an input statement...

input num. User input .49999999

So while on might expect the variable num to be .49999999, QB64 rounds it to .5. Now it will remain .49999999 if the precision is declared as: input num#. What I think is strange is the num is the same as num! but if you write...

PRINT .49999999

Well, that comes out as .49999999. It doesn't get rounded up. I would have thought PRINT .49999999 was the same as PRINT .49999999! but it isn't. PRINT .49999999 returns .5. So it seems PRINT .49999999 acts more like PRINT .4999999# or some other higher precision.

Oh well, I only use string math now, so that old routine just got a trip to the recycle bin.

Pete

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: I don't often work with numbers, but when I do....
« Reply #1 on: September 10, 2021, 02:26:15 am »
I thought that QB64 had a using string function like print using but it does not seem so, neither does it have the VB format function
but you can use snprintf
Code: QB64: [Select]
  1.     SUB snprintf (Dest AS STRING, BYVAL l AS LONG, frmt AS STRING, BYVAL x AS DOUBLE)
  2.  
  3.  
  4. x = .49999999
  5. s = SPC(64)
  6. frmt = "%12.1f"
  7. CALL snprintf(s, 64, frmt, x)
  8. s = LTRIM$(s)
  9.  

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: I don't often work with numbers, but when I do....
« Reply #2 on: September 10, 2021, 02:30:51 am »
Because 0.5 is one of this floating point numbers, which nerver can be represented in binary form exactly. It's because of the way floating points will be converted into the binary system and represented in the SINGLE/DOUBLE/EXTENDED IEEE formats.

0.5 will always result into an infinite period in the mantissa part of the IEEE formats. Some more advanced printing routines will consider such infinite periods and display it as the human would expect it, but the simple PRINT certainly not.

Will look if I still find my old example, but may be @George McGinn may give a better explaination as a member of the IEEE.
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: I don't often work with numbers, but when I do....
« Reply #3 on: September 10, 2021, 02:39:32 am »
Oh damn, forget my last post, it was 0.1 not 0.5 what came to my memory about this matter. It should be possible to exactly represent 0.5, but not 0.1
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: I don't often work with numbers, but when I do....
« Reply #4 on: September 10, 2021, 03:03:25 am »
not being able to edit your post is a discouragement from posting anything especially code, I was going to change
Code: QB64: [Select]
  1. CALL snprintf(s, 64, frmt, x)
to
Code: QB64: [Select]
  1. CALL snprintf(s, Len(s), frmt, x)
  2.  

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: I don't often work with numbers, but when I do....
« Reply #5 on: September 10, 2021, 04:03:26 am »
not being able to edit your post is a discouragement from posting anything especially code, ....

Indeed, it's the worst change the admins did lately, especially for the Progams board. See the post from my signature. Over the years I've improved the wording and appearance of that post to be my designated place to publish my projects to the community, so that I just needed to update the program archives.

Now I've to create a new post and upload a 6MB archive every time I've an update:
1. Waste of database space
2. Old and outdated code/archives remain - the admins removed the link to the historical QB64 versions from the homepage to encourage people to only use the newest QB64 version available for download, but on the other hand they block people here to encourage the same for their projects.

Conclusion:
No more updates here from my side, will just change my signature link to redirect to my own hosting page, when the next updates are ready.

This forum unfortunately does lose its focus more and more, lately even some of my posts disappeared, cause obviously big parts of the BUGS board and of the current DEVELOPMENT topic were deleted without any notice.
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

FellippeHeitor

  • Guest
Re: I don't often work with numbers, but when I do....
« Reply #6 on: September 10, 2021, 11:12:45 am »
I understand the frustration, but unfortunately being able to indefinitely edit one's own posts was being abused. If there was a way to do it selectively by board, I would have set it that way. Our forum software doesn't support the feature, though.

Regarding the BUGS board: posts with SOLVED bugs have been indeed removed. Bugs pending of fixes are still there. Do not consider that board to be permanent anyway, or bugs would too.

Regarding the DEVELOPMENT topic, I am the last one to ever want anything related to it to disappear, since I am the one implementing the new feature. The deletion there was indeed an accident.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: I don't often work with numbers, but when I do....
« Reply #7 on: September 10, 2021, 12:45:55 pm »
How does one abuse editing their own posts?

And even if one person could do such a thing, why not just ban the offenders, rather than eliminate the functionality from all the rest of the users?
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Re: I don't often work with numbers, but when I do....
« Reply #8 on: September 10, 2021, 12:51:38 pm »
I think removing solved bugs is a big mistake.

Suppose I was to search for an issue that I am having. I will never know if a solution existed because it was removed. Maybe the solution was a change to the way I use a statement, but that will never be found, and I will wind up asking the same question again, and people will wonder where I have been.

Or a bug may have been solved by a new development release, and since not everyone is on Discord, they will never see the conversations regarding the bug, if it is ever mentioned there. Again, I may be running an earlier release of QB64, and if I never find the issue I am having using a search on the forum, I will again bring it up.

I would discourage removing solved bugs, or maybe create a read-only forum topic labelled "Solved Bugs" so people can search it for possible solutions to their problems.


I understand the frustration, but unfortunately being able to indefinitely edit one's own posts was being abused. If there was a way to do it selectively by board, I would have set it that way. Our forum software doesn't support the feature, though.

Regarding the BUGS board: posts with SOLVED bugs have been indeed removed. Bugs pending of fixes are still there. Do not consider that board to be permanent anyway, or bugs would too.

Regarding the DEVELOPMENT topic, I am the last one to ever want anything related to it to disappear, since I am the one implementing the new feature. The deletion there was indeed an accident.
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: I don't often work with numbers, but when I do....
« Reply #9 on: September 10, 2021, 01:10:06 pm »
How does one abuse editing their own posts?

And even if one person could do such a thing, why not just ban the offenders, rather than eliminate the functionality from all the rest of the users?
I am with you, and odin, you won't hurt my feelings if you ban me

FellippeHeitor

  • Guest
Re: I don't often work with numbers, but when I do....
« Reply #10 on: September 10, 2021, 01:34:38 pm »
Maybe the solution was a change to the way I use a statement

Posts reporting real bugs go into that board. The scenarios you point out remain in Discussion.

How does one abuse editing their own posts?

Easily.

why not just ban the offenders, rather than eliminate the functionality from all the rest of the users?

Instead of kicking every stray cat entering the cat door, we closed the cat door. I'm sure you'll see how easier a solution that has been.

To everyone in need to update their existing post/code: use the "mark best answer/most recent code" functionality, as already stated before.

Let us please bring this thread back to its original topic.

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Re: I don't often work with numbers, but when I do....
« Reply #11 on: September 10, 2021, 02:10:03 pm »
@FellippeHeitor, That I understand. But what about my second scenario, where a bug was fixed, and say I am a regular or even a new user of QB64, or I'm an occasional user, and you delete a solved bug where it was not corrected in the stable release, yet was fixed in the development build (I'm not talking about major updates, like DEBUG, which you do post in the discussions).  How do I, with limited knowledge of how the community works (or maybe I am not that interested on going deeper into how our community works - I know we have users that are like that, and no, no names).

If you delete these solved bugs, I will never know if it was fixed (I'm betting many do not check GitHub either for commits to bugs). I'm a simple person who just wants to learn programming or be a user of QB64. How then, do I go about finding whether a bug from the stable release has a development fix, if you delete the solved bugs from the forum?

Yes, we can go around in circles debating this, but I do feel that for normal users, there needs to be a place where they can compare what they are experiencing with the location of possible fixes. When you move a discussion from the forum into bugs, then delete it, you remove the entire discussion thread from the forum.

There has to be a better way to preserve this information, or maybe in the BUGS forum section, add verbiage of where a person can find solutions to issues from the stable release.
 
I just think that the little bit of effort to preserve this information, or direct users to find it, will make the experience of using QB64 more enjoyable.

I know from my career in systems design and development, we always coded and documented for a person with a 3rd grade level. I guess back in the stone-age of computers (pre personal computers), not many were as literate as today's users are. I just think that providing for the simplest of users is more advantageous.

Posts reporting real bugs go into that board. The scenarios you point out remain in Discussion.
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

FellippeHeitor

  • Guest
Re: I don't often work with numbers, but when I do....
« Reply #12 on: September 10, 2021, 02:16:21 pm »
Quote
I will never know if it was fixed

Use the latest version. If bug is still present, not been fixed. If it hasn't been fixed, but ever been reported, it'll still be in the BUGS board.

Best place to report bugs is the GitHub repository, for anyone interested.

Let us not make this thread get locked for derailing from the original topic, everyone.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: I don't often work with numbers, but when I do....
« Reply #13 on: September 10, 2021, 08:26:01 pm »
How does one abuse editing their own posts?
And even if one person could do such a thing, why not just ban the offenders, rather than eliminate the functionality from all the rest of the users?

Where people have a tissy fit and go deleting all their posts for some bizarre reason. They leave a lot of `.` posts


Oh well, I only use string math now, so that old routine just got a trip to the recycle bin.
Pete

Why?

I always just did this:
Code: QB64: [Select]
  1. a = .4999999
  2. PRINT INT(a * 10 + .49) / 10
  3.  

Rounds it up to .5

BTY, You and numbers scare me.....
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: I don't often work with numbers, but when I do....
« Reply #14 on: September 10, 2021, 09:27:29 pm »
Didn't we go over rounding to some decimal place a number of times, 2.99999 I think.