Recent Posts

Pages: 1 ... 5 6 [7] 8 9 10
61
QB64 Discussion / Re: QB64 Bounty List
« Last post by Mad Axeman on April 11, 2022, 05:11:46 pm »
Petrol here in the UK works out at around $10.62 a gallon at current exchange rate.
If anything comes of this 'pay per fix' then I have got a few things I would like to see mainly concerning pdf files, barcodes and qrcodes.
62
Programs / Re: Better Bench by Ed Davis
« Last post by Ed Davis on April 11, 2022, 05:05:04 pm »
   y = (-1 * Int((-1 * x * y) / 100)) + y0   <-- isn't a negative * negative = positive?  How is this any different from the ELSE case?

Note this funky code:
Code: [Select]
    if (x < 0 and y > 0) or (x > 0 and y < 0) then
        y = (-1 * Int((-1 * x * y) / 100)) + y0
    else
        y = int(x * y / 100) + y0
    end if

When I originally developed this, I could not get the same results with Python that I got with C.

It turns out that there is no consensus as to whether integer division, when one of the operands is negative, should round towards zero, negative infinity, or positive infinity.

Python and Ruby both round towards negative infinity.  C rounds towards zero.

In order to get the same output from each language (to verify that each language was essentially computing the same thing and doing similar work), I had to figure out how to preclude one of the operands from being negative.

The code checks, and if either x or y is < 0 (but not both), then it multiplies by minus one to force positive division, and then by minus one again at the end to restore the sign.

And I agree, there is probably a better way to do this.  But at the time, I just wanted a solution that worked, and that is what my little mind came up with.

Note that later on, I found out that Python had a integer divide operator, so there was no need to go through the hoops I did.  But, since I had trouble with my "and" and "or" logic and precedence in my own interpreter, I left it in as a sort of unit test :)  And, it does give whatever language is doing this more work to chew on, and more opportunities for optimization.
63
Programs / Re: Better Bench by Ed Davis
« Last post by bplus on April 11, 2022, 05:01:12 pm »
   y = (-1 * Int((-1 * x * y) / 100)) + y0   <-- isn't a negative * negative = positive?  How is this any different from the ELSE case?

looks to me like this forces neg when one or the other is out of bounds but not both.

EDIT
64
Programs / Re: Better Bench by Ed Davis
« Last post by bplus on April 11, 2022, 04:57:54 pm »
Honestly I haven't done any analysis of code yet. I just know the first time I tried I didn't get what I was supposed to and when I made the substitution, the output came out right.

Can FB be so much faster?

Hey! Ed's here!
65
Programs / Re: Better Bench by Ed Davis
« Last post by SMcNeill on April 11, 2022, 04:41:57 pm »
   y = (-1 * Int((-1 * x * y) / 100)) + y0   <-- isn't a negative * negative = positive?  How is this any different from the ELSE case?
66
Programs / Better Bench by Ed Davis
« Last post by bplus on April 11, 2022, 04:15:53 pm »
Generic Basic code convert to QB64 by me for timing and Types:
Code: QB64: [Select]
  1. DefLng A-Z
  2. Dim As Double x, y, xx, yy, start
  3. start = Timer(.001)
  4. accum = 0
  5. count = 0
  6. While count < 1545
  7.     leftedge = -420
  8.     rightedge = 300
  9.     topedge = 300
  10.     bottomedge = -300
  11.     xstep = 7
  12.     ystep = 15
  13.  
  14.     maxiter = 200
  15.  
  16.     y0 = topedge
  17.     While y0 > bottomedge
  18.         x0 = leftedge
  19.         While x0 < rightedge
  20.             y = 0
  21.             x = 0
  22.             thechar = 32
  23.             xx = 0
  24.             yy = 0
  25.             i = 0
  26.             While i < maxiter And xx + yy <= 800
  27.                 xx = Int((x * x) / 200)
  28.                 yy = Int((y * y) / 200)
  29.                 If xx + yy > 800 Then
  30.                     thechar = 48 + i
  31.                     If i > 9 Then
  32.                         thechar = 64
  33.                     End If
  34.                 Else
  35.                     temp = xx - yy + x0
  36.                     If (x < 0 And y > 0) Or (x > 0 And y < 0) Then
  37.                         y = (-1 * Int((-1 * x * y) / 100)) + y0  ' << this line was revised in later post
  38.                     Else
  39.                         y = Int(x * y / 100) + y0
  40.                     End If
  41.                     x = temp
  42.                 End If
  43.  
  44.                 i = i + 1
  45.             Wend
  46.             x0 = x0 + xstep
  47.             accum = accum + thechar
  48.         Wend
  49.         y0 = y0 - ystep
  50.     Wend
  51.  
  52.     If count Mod 300 = 0 Then
  53.         Print accum,
  54.     End If
  55.     count = count + 1
  56.  
  57. Print accum
  58. Print Timer(.001) - start; " seconds"
  59.  
  60. 'This is the output:
  61.  
  62. ' 200574 60372774 120544974 180717174 240889374 301061574 309886830
  63.  
  64.  
I added DEFLNG A-Z and Dim as Double x, y, xx, yy
and I got below 10 secs on Timer with $Checking:Off, 9.61 was best time with everything turned off including Wifi.

Ed has QB64 down for 9.35 secs maybe on better machine...
http://basic4all.epizy.com/index.php?topic=21.msg166#msg166

Can anyone make a significant drop? FreeBasic at top at 1.09 secs
67
QB64 Discussion / Re: Highlight% changes by itself
« Last post by bplus on April 11, 2022, 03:27:11 pm »
Added this in to check running the subs for time:
Code: QB64: [Select]
  1.  If SelectedAnOption% = TRUE% Then
  2. ' debug check the selection code section
  3.             Cls
  4.             Print "You selected "; Highlight%
  5.             _Delay 2
  6.             SelectedAnOption% = FALSE%
  7.             HaltAndDisplay% = TRUE%
  8.  
  9. ' commented out next section, as not ready
  10.             'Select Case Highlight%
  11.             '    Case 1
  12.             '        Call FromNowUntil: SelectedAnOption% = FALSE%
  13.             '    Case 2
  14.  
68
QB64 Discussion / Re: Highlight% changes by itself
« Last post by bplus on April 11, 2022, 03:10:55 pm »
add this in around line 115:
Code: QB64: [Select]
  1. If Highlight% > 8 Then Highlight% = 1  
  2.  

So highlight won't exceed 8

Now I think it will work as intended.
69
QB64 Discussion / Re: Highlight% changes by itself
« Last post by bplus on April 11, 2022, 03:07:48 pm »
Line 110 should be this:
Code: QB64: [Select]
  1.  Highlight% = Highlight% - 1    
  2.  

because the up arrow was not changing the highlight number.
70
QB64 Discussion / Re: Highlight% changes by itself
« Last post by bplus on April 11, 2022, 02:49:09 pm »
Type-O!
Code: QB64: [Select]
  1. Dim Shared RightArroeKey$: rightArrowKey$ = Chr$(0) + "M"
  2.  

need w in arrow where e is!

I found it by watching highlight continuously increasing even when keys not pressed.
Pages: 1 ... 5 6 [7] 8 9 10