Author Topic: Pascal  (Read 6013 times)

0 Members and 1 Guest are viewing this topic.

FellippeHeitor

  • Guest
Re: Pascal
« Reply #15 on: February 26, 2019, 04:06:27 pm »
DIM JD, j, m, d AS LONG

is not the same as

DIM JD AS LONG, j AS LONG, m AS LONG, d AS LONG

Could that be it? Same for:

DIM y4, y1p, gam1, ksi1, mi1, ksi2, mi2, c41p, q, r, dz1, gam2, ksi3, c42p, c43p, dz2, gam3, mi3, z4, c, x3, x1 AS LONG

With that line, only x1 is a LONG. The rest are SINGLE.
« Last Edit: February 26, 2019, 04:09:05 pm by FellippeHeitor »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Pascal
« Reply #16 on: February 26, 2019, 04:09:14 pm »
See if this doesn't work as intended:

Code: QB64: [Select]
  1. ' program J2Jewish
  2. DEFLNG A-Z
  3. DIM JD, j, m, d AS LONG
  4.  
  5. PRINT " np. JD=2057986"
  6. 'INPUT "JD = "; JD
  7. JD = 2057986
  8. JD2Jewish JD, j, m, d
  9. PRINT j; " "; m; " "; d
  10.  
  11.  
  12. FUNCTION c1 (x1 AS LONG)
  13.     c1 = INT((235 * x1 + 1) / 19)
  14.  
  15. FUNCTION q1 (x1 AS LONG)
  16.     q1 = INT(c1(x1) / 1095)
  17.  
  18. FUNCTION r1 (x1 AS LONG)
  19.     r1 = c1(x1) MOD 1095
  20.  
  21. FUNCTION v1 (x1 AS LONG)
  22.     v1 = 32336 * q1(x1) + INT((15 * q1(x1) + 765433 * r1(x1) + 12084) / 25920)
  23.  
  24. FUNCTION v2 (x1 AS LONG)
  25.     v2 = v1(x1) + INT(6 * (v1(x1) / 7)) MOD 2
  26.  
  27. FUNCTION L2 (x1 AS LONG)
  28.     L2 = v2(x1 + 1) - v2(x1)
  29.  
  30. FUNCTION c2 (x1 AS LONG)
  31.     DIM v3, v4 AS LONG
  32.     v3 = 2 * (INT((L2(x1) + 19) / 15) MOD 2)
  33.     v4 = INT((L2(x1 - 1) + 7) / 15) MOD 2
  34.     c2 = v2(x1) + v3 + v4
  35.  
  36. FUNCTION c4 (x1 AS LONG, x3 AS LONG)
  37.     DIM L, c8, c9, c3 AS LONG
  38.     L = c2(x1 + 1) - c2(x1)
  39.     c8 = INT((L + 7) / 2) MOD 15
  40.     c9 = -(INT((385 - L) / 2) MOD 15)
  41.     c3 = INT((384 * x3 + 7) / 13) + c8 * INT((x3 + 4) / 12) + c9 * INT((x3 + 3) / 12)
  42.     c4 = c2(x1) + c3
  43.  
  44. SUB JD2Jewish (JD AS LONG, j AS LONG, m AS LONG, d AS LONG)
  45.  
  46.     DIM y4, y1p, gam1, ksi1, mi1, ksi2, mi2, c41p, q, r, dz1, gam2, ksi3, c42p, c43p, dz2, gam3, mi3, z4, c, x3, x1 AS LONG
  47.  
  48.     y4 = JD - 347821
  49.     q = INT(y4 / 1447)
  50.     r = y4 MOD 1447
  51.     y1p = 49 * q + INT((23 * q + 25920 * r + 13835) / 765433)
  52.     gam1 = y1p + 1
  53.     ksi1 = INT((19 * gam1 + 17) / 235)
  54.     mi1 = gam1 - INT((235 * ksi1 + 1) / 19)
  55.     c41p = c4(ksi1, mi1)
  56.     dz1 = y4 - c41p
  57.     gam2 = gam1 + INT(dz1 / 33)
  58.     ksi2 = INT((19 * gam2 + 17) / 235)
  59.     mi2 = gam2 - INT((235 * ksi2 + 1) / 19)
  60.     c42p = c4(ksi2, mi2)
  61.     dz2 = y4 - c42p
  62.     gam3 = gam2 + INT(dz2 / 33)
  63.     ksi3 = INT((19 * gam3 + 17) / 235)
  64.     x1 = ksi3
  65.     mi3 = gam3 - INT((235 * ksi3 + 1) / 19)
  66.     x3 = mi3
  67.     c43p = c4(ksi3, mi3)
  68.     z4 = y4 - c43p
  69.     c = INT((12 - x3) / 7)
  70.     j = x1 + 1 - c
  71.     m = x3 + 1
  72.     d = z4 + 1
  73.  

Jack more or less had it translated.  The only issue with his program was variable types not matching and thus not passing back through the SUB/FUNCTION routines.

DIM JD, j, m, d AS LONG

vs..

SUB JD2Jewish (JD AS LONG, j AS LONG, m AS LONG, d AS LONG)

Since JD, j, m have no type associated with them, they're defined as SINGLE variables and won't pass values back and forth to the sub where the variables are LONG type.

A simple DEFLNG A-Z at the top of the program corrects most of the issues.  (Removing the % symbol makes certain all our variables are LONG and not INTEGER values which might overflow as well, so I stripped them out also.)

Except for those minor corrections, everything else is Jack's translation.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Ryster

  • Newbie
  • Posts: 77
    • View Profile
Re: Pascal
« Reply #17 on: February 26, 2019, 04:29:58 pm »
It works brilliantly. There is one problem; Well, after the ending line, the code: END SU is the rest of the program, namely:
LOCATE 17, 5
PRINT "Julian Calendar"
e.t.c.
On each of these lines shows an error. It can be eliminated.

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: Pascal
« Reply #18 on: February 26, 2019, 04:31:40 pm »
this version gives the same answer as that of the pascal version, but am not sure it's correct however.
Code: QB64: [Select]
  1. ' program J2Jewish
  2. DEFINT A-Z
  3.  
  4. DIM JD, j, m, d
  5.  
  6. PRINT " np. JD=2057986"
  7. 'NPUT "JD = "; JD
  8. JD = 2057986
  9. JD2Jewish JD, j, m, d
  10. PRINT j; " "; m; " "; d
  11.  
  12.  
  13. FUNCTION c1% (x1)
  14.     c1% = INT((235 * x1 + 1) / 19)
  15.  
  16. FUNCTION q1% (x1)
  17.     q1% = INT(c1%(x1) / 1095)
  18.  
  19. FUNCTION r1% (x1)
  20.     r1% = c1%(x1) MOD 1095
  21.  
  22. FUNCTION v1% (x1)
  23.     v1% = 32336 * q1%(x1) + INT((15 * q1%(x1) + 765433 * r1%(x1) + 12084) / 25920)
  24.  
  25. FUNCTION v2% (x1)
  26.     v2% = v1%(x1) + INT(6 * (v1%(x1) / 7)) MOD 2
  27.  
  28. FUNCTION L2% (x1)
  29.     L2% = v2%(x1 + 1) - v2(x1)
  30.  
  31. FUNCTION c2% (x1)
  32.     DIM v3, v4
  33.     v3 = 2 * (INT((L2%(x1) + 19) / 15) MOD 2)
  34.     v4 = INT((L2%(x1 - 1) + 7) / 15) MOD 2
  35.     c2 = v2%(x1) + v3 + v4
  36.  
  37. FUNCTION c4% (x1, x3)
  38.     DIM L, c8, c9, c3
  39.     L = c2%(x1 + 1) - c2%(x1)
  40.     c8 = INT((L + 7) / 2) MOD 15
  41.     c9 = -(INT((385 - L) / 2) MOD 15)
  42.     c3 = INT((384 * x3 + 7) / 13) + c8 * INT((x3 + 4) / 12) + c9 * INT((x3 + 3) / 12)
  43.     c4 = c2%(x1) + c3
  44.  
  45. SUB JD2Jewish (JD, j, m, d)
  46.  
  47.     DIM y4, y1p, gam1, ksi1
  48.     DIM mi1, ksi2, mi2, c41p
  49.     DIM q, r, dz1, gam2, ksi3
  50.     DIM c42p, c43p, dz2, gam3
  51.     DIM mi3, z4, c, x3, x1
  52.  
  53.     y4 = JD - 347821
  54.     q = INT(y4 / 1447)
  55.     r = y4 MOD 1447
  56.     y1p = 49 * q + INT((23 * q + 25920 * r + 13835) / 765433)
  57.     gam1 = y1p + 1
  58.     ksi1 = INT((19 * gam1 + 17) / 235)
  59.     mi1 = gam1 - INT((235 * ksi1 + 1) / 19)
  60.     c41p = c4(ksi1, mi1)
  61.     dz1 = y4 - c41p
  62.     gam2 = gam1 + INT(dz1 / 33)
  63.     ksi2 = INT((19 * gam2 + 17) / 235)
  64.     mi2 = gam2 - INT((235 * ksi2 + 1) / 19)
  65.     c42p = c4(ksi2, mi2)
  66.     dz2 = y4 - c42p
  67.     gam3 = gam2 + INT(dz2 / 33)
  68.     ksi3 = INT((19 * gam3 + 17) / 235)
  69.     x1 = ksi3
  70.     mi3 = gam3 - INT((235 * ksi3 + 1) / 19)
  71.     x3 = mi3
  72.     c43p = c4(ksi3, mi3)
  73.     z4 = y4 - c43p
  74.     c = INT((12 - x3) / 7)
  75.     j = x1 + 1 - c
  76.     m = x3 + 1
  77.     d = z4 + 1
  78.  

Offline Ryster

  • Newbie
  • Posts: 77
    • View Profile
Re: Pascal
« Reply #19 on: February 27, 2019, 10:32:11 am »
A request to change the code.
The code works properly, but not completely according to my plan. In the current code, JD is given numerically. In my program, JD is calculated by another code placed earlier. So I want it to be automatically downloaded by the Hebrew code.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Pascal
« Reply #20 on: February 27, 2019, 03:17:51 pm »
Hi Ryster

piece by piece the project comes out!
JD is the result of another piece (block) of code... a Function? A Sub?
it is easy...in pseudocode...

Quote
FUNCTION HebrewCode AS LONG
calculations
calculations
calculations
END FUNCTION

Quote
' program J2Jewish
DEFLNG A-Z

DIM JD, j, m, d

'PRINT " np. JD=2057986"
'INPUT "JD = "; JD
JD = HebrewCode    '2057986
JD2Jewish JD, j, m, d

this can be useful!....
or you must post the other piece of code if you are not so able to translate it into QB64/BASIC.
;-)

Programming isn't difficult, only it's  consuming time and coffee

Offline Ryster

  • Newbie
  • Posts: 77
    • View Profile
Re: Pascal
« Reply #21 on: February 27, 2019, 03:34:59 pm »
JD is calculated from the usual formula. In addition, what I wrote in an earlier post (no answer) about the fact that after the Hebrew code whatever is there displays error in the first line. This is how you have to finish the Hebrew code so that you can write next instructions not related to Hebrew. So only these two problems remain to be solved and everything will be ok. Thank you for your willingness to help.