QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Ryster on February 25, 2019, 03:49:06 pm

Title: Pascal
Post by: Ryster on February 25, 2019, 03:49:06 pm
Welcome.
Would any of the honorable Forum members undertake to translate the code written in Pascal to QB64 ?. The code has about 60 lines.
Regards Ryster
Title: Re: Pascal
Post by: SMcNeill on February 25, 2019, 04:03:54 pm
Can you share it?  It’s been a while, but I used to program in pascal ages ago.
Title: Re: Pascal
Post by: Pete on February 25, 2019, 04:28:15 pm
Pascal is very similar to BASIC. I tried it several years go, when it looked like QB was headed to the graveyard. Fortunately QB64 got started before I spent much time in Pascal. My opinion was you can do more with '64.

Yes, share the code and what the program is supposed to do.

Pete
Title: Re: Pascal
Post by: TempodiBasic on February 25, 2019, 06:11:11 pm
@Pete
Pascal = QB ?
in my experience (TurboPascal) this is not quite right!
1. very restrictive rules to code...  at first phase  declaration at second phase coding the algoritm (so often while I was starting to declare each variable I had already forgotten the main idea how to do something and  my fantasy was stopped very quickly!)
2. fine to have  inline assembler, calling to OS functions like interrupts (no coito interruptus censored), pointers, OOP (starting from 5.5 to up)

or do you think about https://it.wikipedia.org/wiki/COMAL (https://it.wikipedia.org/wiki/COMAL) COMAL?
Title: Re: Pascal
Post by: Pete on February 25, 2019, 06:27:23 pm
It's coding statements are very similar to BASIC. The other stuff? WHOGAS!

Pete :D
Title: Re: Pascal
Post by: TempodiBasic on February 25, 2019, 06:38:19 pm
I'm absolutely agreed with you!
(sob I don't remember who is WHOGAS! :-)  )
And I found very similar also the FORTRAN to the BASIC statements.

But how hard Pascal  is to force you to declare and then use something I find no equal in my little experience!
Good night ( at my clock) !
Title: Re: Pascal
Post by: Ryster on February 26, 2019, 10:59:01 am
Thank you for your interest.
Pram deals with the conversion of Julian Day (JD) to the Hebrew calendar. Input data: (JD) e.g. 2458541. Output data: day, month, year. As for JD, there is no need to use the Input function because JD will be downloaded automatically from another subprogram. Thank you very much to those who will change the code.

program J2Jewish;
{$APPTYPE CONSOLE}
uses
  SysUtils,
  math;
procedure JD2Jewish(JD:integer; var j,m,d:integer);
function c4(x1,x3:integer):integer;
function c1(x1:integer):integer;
begin
c1:=floor((235*x1+1)/19);
end;
function q(x1:integer):integer;
begin
q:=floor(c1(x1)/1095);
end;
function r(x1:integer):integer;
begin
r:=c1(x1) mod 1095;
end;
function v1(x1:integer):integer;
begin
v1:=32336*q(x1) + floor((15*q(x1)+765433*r(x1)+12084)/25920);
end;
function v2(x1:integer):integer;
begin
v2:=v1(x1) + floor(6*(v1(x1)/7)) mod 2;
end;
function L2(x1:integer):integer;
begin
L2:=v2(x1+1) - V2(x1);
end;
function c2(x1:integer):integer;
var v3,v4:integer;
begin
v3:=2*(floor((L2(x1)+19)/15) mod 2);
v4:=floor((L2(x1-1)+7)/15) mod 2;
c2:=v2(x1)+v3+v4
end;
var L,c8,c9,c3:integer;
begin
L:=c2(x1+1)-c2(x1);
c8:=floor((L+7)/2) mod 15;
c9:=-(floor((385-L)/2) mod 15);
c3:=floor((384*x3+7)/13) + c8*floor((x3+4)/12) + c9*floor((x3+3)/12);
c4:=c2(x1)+c3;
end;

var
    y4,y1p,gam1,ksi1,mi1,ksi2,mi2,c41p,q,r,dz1,gam2,ksi3,c42p,c43p,dz2,gam3,mi3,z4,c,x3,x1:integer;

begin
y4:=JD-347821;
q:=floor(y4/1447);
r:=y4 mod 1447;
y1p:=49*q+floor((23*q+25920*r+13835)/765433);
gam1:=y1p+1;
ksi1:=floor((19*gam1+17)/235);
mi1:=gam1-floor((235*ksi1+1)/19);
c41p:=c4(ksi1,mi1);
dz1:=y4-c41p;
gam2:=gam1 + floor(dz1/33);
ksi2:=floor( (19*gam2+17)/235 );
mi2:=gam2-floor( (235*ksi2+1)/19 );
c42p:=c4(ksi2,mi2);
dz2:=y4-c42p;
gam3:=gam2 + floor(dz2/33);
ksi3:=floor( (19*gam3+17)/235 );  x1:=ksi3;
mi3:=gam3-floor( (235*ksi3+1)/19 ); x3:=mi3;
c43p:=c4(ksi3,mi3);
z4:=y4-c43p;
c:=floor((12-x3)/7);
j:=x1+1-c;
m:=x3+1;
d:=z4+1;
end;
var JD:integer;
    j,m,d:integer;
begin
writeln(' np. JD=2057986');
write('JD ='); readln(JD);
//JD:=2057986;
JD2Jewish(JD,  j,m,d);
writeln(j,' ',m,' ',d);
readln;
end.
Title: Re: Pascal
Post by: jack on February 26, 2019, 01:57:34 pm
I refactored the code to make it easier to follow and to translate to QB64
Code: QB64: [Select]
  1. program J2Jewish;
  2. //{$APPTYPE CONSOLE}
  3. uses
  4.         SysUtils,
  5.         math;
  6.  
  7. begin
  8.         c1:=floor((235*x1+1)/19);
  9.  
  10. begin
  11.         q:=floor(c1(x1)/1095);
  12.  
  13. begin
  14.         r:=c1(x1) mod 1095;
  15.  
  16. begin
  17.         v1:=32336*q(x1) + floor((15*q(x1)+765433*r(x1)+12084)/25920);
  18.  
  19. begin
  20.         v2:=v1(x1) + floor(6*(v1(x1)/7)) mod 2;
  21.  
  22. begin
  23.         L2:=v2(x1+1) - V2(x1);
  24.  
  25. var v3,v4:integer;
  26. begin
  27.         v3:=2*(floor((L2(x1)+19)/15) mod 2);
  28.         v4:=floor((L2(x1-1)+7)/15) mod 2;
  29.         c2:=v2(x1)+v3+v4
  30.  
  31. var L,c8,c9,c3:integer;
  32. begin
  33.         L:=c2(x1+1)-c2(x1);
  34.         c8:=floor((L+7)/2) mod 15;
  35.         c9:=-(floor((385-L)/2) mod 15);
  36.         c3:=floor((384*x3+7)/13) + c8*floor((x3+4)/12) + c9*floor((x3+3)/12);
  37.         c4:=c2(x1)+c3;
  38.  
  39. procedure JD2Jewish(JD:integer; var j,m,d:integer);
  40.  
  41. var
  42.     y4,y1p,gam1,ksi1,mi1,ksi2,mi2,c41p,q,r,dz1,gam2,ksi3,c42p,c43p,dz2,gam3,mi3,z4,c,x3,x1:integer;
  43.  
  44. begin
  45.         y4:=JD-347821;
  46.         q:=floor(y4/1447);
  47.         r:=y4 mod 1447;
  48.         y1p:=49*q+floor((23*q+25920*r+13835)/765433);
  49.         gam1:=y1p+1;
  50.         ksi1:=floor((19*gam1+17)/235);
  51.         mi1:=gam1-floor((235*ksi1+1)/19);
  52.         c41p:=c4(ksi1,mi1);
  53.         dz1:=y4-c41p;
  54.         gam2:=gam1 + floor(dz1/33);
  55.         ksi2:=floor( (19*gam2+17)/235 );
  56.         mi2:=gam2-floor( (235*ksi2+1)/19 );
  57.         c42p:=c4(ksi2,mi2);
  58.         dz2:=y4-c42p;
  59.         gam3:=gam2 + floor(dz2/33);
  60.         ksi3:=floor( (19*gam3+17)/235 );  x1:=ksi3;
  61.         mi3:=gam3-floor( (235*ksi3+1)/19 ); x3:=mi3;
  62.         c43p:=c4(ksi3,mi3);
  63.         z4:=y4-c43p;
  64.         c:=floor((12-x3)/7);
  65.         j:=x1+1-c;
  66.         m:=x3+1;
  67.         d:=z4+1;
  68.  
  69. var JD:integer;
  70.     j,m,d:integer;
  71. begin
  72.         writeln(' np. JD=2057986');
  73.         write('JD ='); readln(JD);
  74.         //JD:=2057986;
  75.         JD2Jewish(JD,  j,m,d);
  76.         writeln(j,' ',m,' ',d);
  77.         readln;
  78.  
Title: Re: Pascal
Post by: Ryster on February 26, 2019, 02:09:55 pm
Thanks, it looks nicer now.
Title: Re: Pascal
Post by: SMcNeill on February 26, 2019, 02:40:28 pm
Most of these are pretty straightforward to translate:

function c1(x1:integer):integer;
begin
   c1:=floor((235*x1+1)/19);
end;


FUNCTION c1% (x1 AS INTEGER)
    c1% = (235 * x1 + 1) \ 19
END FUNCTION

*************

If nobody else gets around to it before me, I’ll work on translating it later tonight/tomorrow.  Today I’m booked up doing stuff with the wife, but my schedule should hopefully clear by tomorrow, I’m thinking.  (I can never be 100% certain until my wife verifies my schedule though.  After 26 years of marriage, I know my free time depends a lot more on HER schedule than it does mine.)  ;D
Title: Re: Pascal
Post by: jack on February 26, 2019, 03:05:35 pm
there's something you should know, integer is 16-bit
so how this is supposed to work when 2057986 overflows a 16-bit integer, I don't know.
Title: Re: Pascal
Post by: Ryster on February 26, 2019, 03:21:07 pm
SMcNeill
You're right, your wife is more important.
Title: Re: Pascal
Post by: SMcNeill on February 26, 2019, 03:22:54 pm
there's something you should know, integer is 16-bit
so how this is supposed to work when 2057986 overflows a 16-bit integer, I don't know.

LONGs would work, if INTEGER doesn’t.  ;)
Title: Re: Pascal
Post by: Ryster on February 26, 2019, 03:34:36 pm
For test purposes. No months names.

https://drive.google.com/file/d/1jWkbtj9RNBDShhGyS8zMjt5BWeMUZ9HD/view?usp=sharing
Title: Re: Pascal
Post by: jack on February 26, 2019, 03:49:34 pm
I can't get QB64 to produce the right answer
Code: QB64: [Select]
  1. ' program J2Jewish
  2.  
  3. DIM JD, j, m, d AS LONG
  4.  
  5. PRINT " np. JD=2057986"
  6. 'NPUT "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.  
however, the following FreeBasic code gives the same answer as that of the pascal version, namely 17, 1, 28
Code: QB64: [Select]
  1. ' program J2Jewish
  2.  
  3. function c1( byval x1 as short) as short
  4.         c1=int((235*x1+1)/19)
  5.  
  6. function q1(byval x1 as short) as short
  7.         q1=int(c1(x1)/1095)
  8.  
  9. function r1(byval x1 as short) as short
  10.         r1=c1(x1) mod 1095
  11.  
  12. function v1(byval x1 as short) as short
  13.         v1=32336*q1(x1) + int((15.0*q1(x1)+765433.0*r1(x1)+12084)/25920)
  14.  
  15. function v2(byval x1 as short) as short
  16.         v2=v1(x1) + int(6.0*(v1(x1)/7)) mod 2
  17.  
  18. function L2(byval x1 as short) as short
  19.         L2=v2(x1+1) - V2(x1)
  20.  
  21. function c2(byval x1 as short) as short
  22.         dim as short v3, v4
  23.         v3=2*(int((L2(x1)+19)/15) mod 2)
  24.         v4=int((L2(x1-1)+7)/15) mod 2
  25.         c2=v2(x1)+v3+v4
  26.  
  27. function c4(byval x1  as short, x3 as short) as short
  28.         dim as short L, c8, c9, c3
  29.         L=c2(x1+1)-c2(x1)
  30.         c8=int((L+7)/2) mod 15
  31.         c9=-(int((385-L)/2) mod 15)
  32.         c3=int((384.0*x3+7)/13) + c8*int((x3+4)/12) + c9*int((x3+3)/12)
  33.         c4=c2(x1)+c3
  34.  
  35. sub JD2Jewish(byval JD as short, byref j as short, byref m as short, byref d as short)
  36.  
  37.         dim as short y4,y1p,gam1,ksi1,mi1,ksi2,mi2,c41p,q,r,dz1,gam2,ksi3,c42p,c43p,dz2,gam3,mi3,z4,c,x3,x1
  38.  
  39.         y4=JD-347821
  40.         q=int(y4/1447)
  41.         r=y4 mod 1447
  42.         y1p=49*q+int((23.0*q+25920.0*r+13835)/765433)
  43.         gam1=y1p+1
  44.         ksi1=int((19.0*gam1+17)/235)
  45.         mi1=gam1-int((235.0*ksi1+1)/19)
  46.         c41p=c4(ksi1,mi1)
  47.         dz1=y4-c41p
  48.         gam2=gam1 + int(dz1/33)
  49.         ksi2=int( (19.0*gam2+17)/235 )
  50.         mi2=gam2-int( (235.0*ksi2+1)/19 )
  51.         c42p=c4(ksi2,mi2)
  52.         dz2=y4-c42p
  53.         gam3=gam2 + int(dz2/33)
  54.         ksi3=int( (19.0*gam3+17)/235 )
  55.         x1=ksi3
  56.         mi3=gam3-int( (235.0*ksi3+1)/19 )
  57.         x3=mi3
  58.         c43p=c4(ksi3,mi3)
  59.         z4=y4-c43p
  60.         c=int((12-x3)/7)
  61.         j=x1+1-c
  62.         m=x3+1
  63.         d=z4+1
  64.  
  65. 'main
  66.         dim as short JD, j, m, d
  67.  
  68.         print " np. JD=2057986"
  69.         'input "JD = "; JD
  70.         JD=2057986
  71.         JD2Jewish(JD,  j, m, d)
  72.         print j;" "; m; " "; d
  73.  
Title: Re: Pascal
Post by: FellippeHeitor 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.
Title: Re: Pascal
Post by: SMcNeill 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.  ;)
Title: Re: Pascal
Post by: Ryster 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.
Title: Re: Pascal
Post by: jack 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.  
Title: Re: Pascal
Post by: Ryster 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.
Title: Re: Pascal
Post by: TempodiBasic 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.
;-)

Title: Re: Pascal
Post by: Ryster 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.