Author Topic: What Happened?  (Read 800 times)

B+

  • Hero Member
  • *****
  • Posts: 802
    • View Profile
What Happened?
« on: 30. August 2018, 03:52:32 »
Hi Chris,

Do you know why this no longer works?
Code: [Select]
for i in seq(0, 2*pi, 360/15+1) do ? round(deg(i)), ((10000*sin(i))\1)*.0001
At one time it printed out a SIN table, every 15 degrees.

chrisws

  • Moderator
  • Newcomer
  • *****
  • Posts: 32
    • View Profile
Re: What Happened?
« Reply #1 on: 30. August 2018, 12:32:02 »
It's a subtle bug related to internal data types. I was going to release an update sometime soon, so can include the fix.

Cheers,
Chris

B+

  • Hero Member
  • *****
  • Posts: 802
    • View Profile
Re: What Happened?
« Reply #2 on: 30. August 2018, 14:32:22 »
OK

BTW I should mention the version 0,12,11 SDL Win 64 Dec 28, 2017.

I probably wrote the original line of code (mod by jasali) with version 12.9 or earlier.

ScriptBasic

  • Guest
Re: What Happened?
« Reply #3 on: 30. August 2018, 19:17:28 »
Chris,

Let me know if there is anything you need to support your board on the All BASIC forum.

B+

  • Hero Member
  • *****
  • Posts: 802
    • View Profile
Re: What Happened? Fixed in SmallBASIC 0.12.13
« Reply #4 on: 13. September 2018, 17:01:53 »
Fixed!
Code: [Select]
REM SmallBASIC "One statement SIN test"
REM created: 13/09/2018 seq test.bas B+

for i in seq(0, 360, 25) do ? "i = ";i;", rad(i) = ";rad(i);", sin(rad(i)) = ";sin(rad(i))

So do you like the labeled Table?

B+

  • Hero Member
  • *****
  • Posts: 802
    • View Profile
Re: What Happened?
« Reply #5 on: 28. October 2018, 17:08:59 »
What happened to SmallBASIC's Random number generator? Was it always this bad?

Here I was testing 1,000,000 random numbers * 1000000 to compare Sort methods, and did not get much variation!
Code: [Select]
REM SmallBASIC
REM created: 28/10/2018

'Compare RussianSorting presented by Danilin to a Basic standard QuickSort by B+ 2018-10-28"
RANDOMIZE TIMER

' Here is the only relevant parts of Danilin
CONST n = 1000000
DIM d(n) ' single
DIM a(n) ' single
DIM QS(n) ' to compare to Danilin's "simple" code

' Make a sample set of test data
FOR i = 1 TO n
    r = RND * n
    d(i) = r
    QS(i) = r
NEXT

' Since Danilin does not provide us with "c:/N.txt" file data, can't be important to his demo
age = 1 + LOG(n) / LOG(2)
start = TIMER
IF age > 0 THEN
    RussianSortingHalvesDAV 1, n, 1, age
END IF
finish = TIMER
PRINT finish - start; "second "
IF n > 100 THEN stopper = 100 ELSE stopper = n
FOR i = 1 TO stopper
    PRINT d(i); ", ";
NEXT
DanilinTime = finish - start
PRINT: PRINT: INPUT "Now for the Quick Sort Test, press enter...", enter$
CLS

'now try good ole Quick Sort
start = TIMER
qSort 1, n
finish = TIMER
PRINT finish - start; "sec."
IF n > 100 THEN stopper = 100 ELSE stopper = n
FOR i = 1 TO stopper
    PRINT d(i); ", ";
NEXT
QSortTime = finish - start
PRINT: PRINT: PRINT "Ha, ha, ha QSort took "; INT(QSortTime / DanilinTime * 1000) / 1000; " times longer than Danilin's Sort!"
PAUSE


SUB RussianSortingHalvesDAV (ab, yz, part, age)
  local i, summa, middle, abc, xyz
    IF yz - ab < 1 THEN EXIT SUB

    FOR i = ab TO yz '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> really a time waster and String Array Buster here!!!!!
        summa = summa + d(i)
    NEXT
    middle = summa / (yz - ab + 1)

    abc = ab - 1
    xyz = yz + 1

    FOR i = ab TO yz
        IF d(i) < middle THEN abc = abc + 1: a(abc) = d(i): ELSE xyz = xyz - 1: a(xyz) = d(i)
    NEXT

    FOR i = ab TO yz: d(i) = a(i): NEXT

    IF part < age THEN
        IF abc >= ab THEN RussianSortingHalvesDAV ab, abc, part + 1, age
        IF xyz <= yz THEN RussianSortingHalvesDAV xyz, yz, part + 1, age
    END IF

END SUB

'QS is DIM SHARED to compare to Danilin's method that needs two DIM SHARED Arrays for his SUB
SUB qSort (start, finish)
  local Hi, Lo, Middle
    'DIM Hi AS LONG, Lo AS LONG, Middle AS SINGLE
    Hi = finish: Lo = start
    Middle = QS((Lo + Hi) / 2) 'find middle of array
    REPEAT
        WHILE QS(Lo) < Middle: Lo = Lo + 1: WEND
        WHILE QS(Hi) > Middle: Hi = Hi - 1: WEND
        IF Lo <= Hi THEN
            SWAP QS(Lo), QS(Hi)
            Lo = Lo + 1: Hi = Hi - 1
        END IF
    UNTIL Lo > Hi
    IF Hi > start THEN qSort start, Hi
    IF Lo < finish THEN qSort Lo, finish
END SUB


You can see the repetition of values in first 100 after sort. Jump from <1 to 30.xxx
« Last Edit: 28. October 2018, 19:03:49 by B+ »