Author Topic: fibonacci(4784969)  (Read 31647 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: fibonacci(4784969)
« Reply #75 on: June 15, 2019, 10:53:31 PM »
GMP works great with SB. Very seamless operation.

GMP User Manual

What does gmp2::mul_si do differently than a standard gmp2::mul?
« Last Edit: June 16, 2019, 12:40:14 AM by John »

Offline AIR

  • BASIC Developer
  • Posts: 932
  • Coder
Re: fibonacci(4784969)
« Reply #76 on: June 16, 2019, 10:04:47 AM »
In the case of SB, typically no difference (if using integers) because of the way I wrapped the GMP api.

In the GMP api itself, *_si indicates that you are passing a "signed integer" as a parameter. *_ui would be an "unsigned integer".

Other numeric types are represented in similar fashion (they're not implemented in the SB Module), the documentation link you posted has more details under the Integer/Rational/Floating-Point function sections.


AIR.

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: fibonacci(4784969)
« Reply #77 on: June 16, 2019, 10:42:13 AM »
Thanks!

Another mystery solved.

If you were to expand on the GMP2 extension module, what areas would SB benefit most from?
« Last Edit: June 16, 2019, 10:45:28 AM by John »

Offline AIR

  • BASIC Developer
  • Posts: 932
  • Coder
Re: fibonacci(4784969)
« Reply #78 on: June 16, 2019, 06:46:40 PM »
Thanks!

Another mystery solved.

If you were to expand on the GMP2 extension module, what areas would SB benefit most from?

In order to answer that, I'd need an actual use case.

At the very least, support for floating point numbers should be on the todo list.

Take a look at this Bacon GMP module, to get an idea of which functions MIGHT be needed.

AIR.

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: fibonacci(4784969)
« Reply #79 on: June 16, 2019, 06:56:00 PM »
The BaCon GMP library is almost plug & play additions to the GMP2 module.

The BaCon GMP library looks to only return a max of 100 digits. The function selection was helpful..

It would be great if we had a set of GMP operator functions that would match SB's native set.
« Last Edit: June 16, 2019, 07:26:22 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: fibonacci(4784969)
« Reply #80 on: June 16, 2019, 07:35:45 PM »
ScriptBasic allows creating COMMANDS as well as functions. I've only done it once with a IFF command. If we were to to do the GMP2 functions as commands there would be little difference in syntax for expressions.

++ = add
-- = sub
** = mul
// = divide
....

c = GMP2::a ++ b

If no MODLE and just DECLARE COMMAND

c = a ++ b
« Last Edit: June 16, 2019, 07:47:48 PM by John »

Offline AIR

  • BASIC Developer
  • Posts: 932
  • Coder
Re: fibonacci(4784969)
« Reply #81 on: June 16, 2019, 08:08:47 PM »
Any chance of a working example?

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: fibonacci(4784969)
« Reply #82 on: June 16, 2019, 08:10:47 PM »
The IIF example in the trial extension module.

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: fibonacci(4784969)
« Reply #83 on: June 16, 2019, 09:35:31 PM »
I added cmp to the gmp2 extension module but I'm unable to push anything anymore.

Maybe this function isn't need as SB is fully capable of comparing strings.

Code: C
  1. /**
  2. =section cmp
  3. =H cmp
  4.  
  5. cmp mpz_t objects
  6. */
  7. besFUNCTION(cmp)
  8.   pModuleObject p;
  9.   char *s, *t;
  10.  
  11.   int i, rtn;
  12.  
  13.   p = (pModuleObject)besMODULEPOINTER;
  14.  
  15.   besARGUMENTS("zz")
  16.     &s,&t
  17.   besARGEND
  18.  
  19.   mpz_set_str(g_Op1, s, 10);
  20.   mpz_set_str(g_Op2, t, 10);
  21.   rtn = mpz_cmp(g_Op1, g_Op2);
  22.  
  23.   besRETURN_LONG(rtn);
  24. besEND
  25.  

It returns a -1 if they are not equal and 0 if they are.
« Last Edit: June 16, 2019, 10:04:32 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: fibonacci(4784969)
« Reply #84 on: June 19, 2019, 07:40:37 PM »
Hi AIR,

Any luck with creating a command like ++ with SB?

Offline AIR

  • BASIC Developer
  • Posts: 932
  • Coder
Re: fibonacci(4784969)
« Reply #85 on: June 19, 2019, 08:15:18 PM »
Nope.  Would need a parser to handle that.

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: fibonacci(4784969)
« Reply #86 on: June 19, 2019, 08:27:05 PM »
That sucks!

 Commands have always been the final SB frontier for me.

I thought the reason ++ was reserved was for just this purpose. The ++ becomes the function (command) name which has 2 arguments. (prefix/suffix)
« Last Edit: June 19, 2019, 08:34:24 PM by John »

Offline AIR

  • BASIC Developer
  • Posts: 932
  • Coder
Re: fibonacci(4784969)
« Reply #87 on: June 19, 2019, 09:23:42 PM »
Where is that documented?

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: fibonacci(4784969)
« Reply #88 on: June 19, 2019, 09:27:29 PM »
The keywords list shows the reserved symbol pair. You will have to dig for examples beyond IFF in trial. I'm trying to dig up what I can find.

For grins try the +! syntax in scriba. The returned message should be enlightening.
« Last Edit: June 20, 2019, 09:39:55 AM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: fibonacci(4784969)
« Reply #89 on: June 20, 2019, 09:26:53 AM »
It looks like ++ isn't one of the reserved symbol pairs. These are the options for addition.


+^    +<    +>    +?    +=    +*    +/    +%    +!    +#    +&    +\    +`    +'    
+@


+! looks interesting.