Qbasicnews.com
August 25, 2019, 11:29:44 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: 1 ... 5 6 [7]
  Print  
Author Topic: Challenge: Algorithms having only one line of code.  (Read 33296 times)
Ralph
Ancient Guru
****
Posts: 544


« Reply #90 on: March 31, 2006, 05:20:49 PM »

O.K., Moneo, you have had a few responses.  Now, what are you going to do with them?  I envision you will cull them, arrange them in some order, with a nice description preceding each one, and sort of customize there presentation, besides providing a neat identifiction tag for each one.  If that is your intention, it might be a good idea to let the folks know your intentions, publish what you have so far, and further invite more posts on the subject.

Regards,

Ralph
Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Moneo
Na_th_an
*****
Posts: 1971


« Reply #91 on: March 31, 2006, 11:06:58 PM »

Quote from: "Ralph"
O.K., Moneo, you have had a few responses.  Now, what are you going to do with them?  I envision you will cull them, arrange them in some order, with a nice description preceding each one, and sort of customize there presentation, besides providing a neat identifiction tag for each one.  If that is your intention, it might be a good idea to let the folks know your intentions, publish what you have so far, and further invite more posts on the subject.

Regards,
Ralph

I revived this old thread for the purpose of correcting a rounding algorithm that I had posted back in 2003. I was concerned that someone might be using that old algorithm and sometimes getting wrong results while rounding negative numbers.

Then people started posting other algorithms, and the thread got started up again.

I already have a tutorial on algorithms which I wrote a few years ago for QBNZ. I might consider updating this tutorial for publication on the QB Express, in which case I'll scan this entire thread again to pick up any algorithms which in my opinion are worth including. This tutorial already gives credit to the author of each algorithm.

I agree with you had I intended to publish these algorithms. Yes, letting everyone know would have been a good idea. However, as I said before, this was not my intention. If you have the inclination to publish these algorithms, you're entirely free to do so.
*****
Logged
yetifoot
Ancient Guru
****
Posts: 575



« Reply #92 on: April 01, 2006, 11:28:43 AM »

Heres the plan

1.  Ask for Algorithms.
2. HuhHuh
3. Profit
Logged

EVEN MEN OF STEEL RUST.
yetifoot
Ancient Guru
****
Posts: 575



« Reply #93 on: April 26, 2006, 12:04:27 PM »

Heres a couple i came across recently that i found quite interesting.  They are for testing if an addition or subtraction causes an overflow (ie the result is out of signed range)

These examples assume that a and b are 16-bit signed values.  This can be changed by changing the AND &H8000 to other values (ie &H80 for 8-bit).

Here is a link to a topic where redcrab explained to me exactly how they work

http://www.freebasic.net/forum/viewtopic.php?t=3914

Addition
Code:
overflow = ((a XOR (NOT b)) AND (a XOR (a + b)) AND &H8000) <> 0


Subtraction
Code:
overflow = ((a XOR b) AND (a XOR (a - b)) AND &H8000) <> 0
Logged

EVEN MEN OF STEEL RUST.
Moneo
Na_th_an
*****
Posts: 1971


« Reply #94 on: April 26, 2006, 09:49:29 PM »

Vert good, Yetifoot, these algorithms for detecting overflow could come in handy for not having to use ON ERROR.
*****
Logged
yetifoot
Ancient Guru
****
Posts: 575



« Reply #95 on: April 27, 2006, 01:37:49 PM »

I think they would have to be modified for use in QB, because the code itself will cause an overflow (due to a+b, or a-b).  They are more useful for FB, because FB does not do overflow checks (unless it's switched on with -ex, or -exx).
Logged

EVEN MEN OF STEEL RUST.
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #96 on: May 03, 2006, 02:55:30 PM »

QBasic does not signal overflow if compiled without the /d  option. Only interpreted QB always signals overflows, and your code would fail there.
Logged

Antoni
yetifoot
Ancient Guru
****
Posts: 575



« Reply #97 on: May 05, 2006, 09:01:07 AM »

Quote from: "Antoni Gual"
QBasic does not signal overflow if compiled without the /d  option. Only interpreted QB always signals overflows, and your code would fail there.


Thanks for the clarification, I have not used QB/QBASIC much so I don't know much about it.
Logged

EVEN MEN OF STEEL RUST.
Pages: 1 ... 5 6 [7]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!