Author Topic: GNU Scientific Library (GSL)  (Read 3359 times)

support

  • Administrator
  • *****
  • Posts: 844
    • Script BASIC Open Source Project
GNU Scientific Library (GSL)
« on: May 29, 2011, 09:09:12 PM »
I have finished the Elementary Functions portion of the ScriptBasic extension module for the GSL library.

Code: [Select]
/*
   GNU Scientific Library
   Based on GSL 1.15
   Interface By: John Spikowski
   Refinements By: Armando I. Rivera (AIR)
   Version 0.01
*/

#include <stdio.h>
#include "../../basext.h"
#include <gsl/gsl_math.h>
     
besVERSION_NEGOTIATE
    return (int)INTERFACE_VERSION;
besEND

besSUB_START

besEND

besSUB_FINISH

besEND

/* Elementary Functions */

besFUNCTION(_log1p)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_log1p(x));
besEND


besFUNCTION(_expm1)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_expm1(x));
besEND


besFUNCTION(_hypot)
  double x,y;

  besARGUMENTS("rr")
    &x,&y
  besARGEND 

  besRETURN_DOUBLE(gsl_hypot(x, y));
besEND


besFUNCTION(_hypot3)
  double x,y,z;
 
  besARGUMENTS("rrr")
    &x,&y,&z
  besARGEND 

  besRETURN_DOUBLE(gsl_hypot3(x, y, z));
besEND


besFUNCTION(_acosh)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_acosh(x));
besEND


besFUNCTION(_asinh)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_asinh(x));
besEND


besFUNCTION(_atanh)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_atanh(x));
besEND


besFUNCTION(_ldexp)
  double x;
  int y;

  besARGUMENTS("ri")
    &x,&y
  besARGEND 

  besRETURN_DOUBLE(gsl_ldexp(x, y));
besEND


besFUNCTION(_frexp)
  double f;
  LEFTVALUE e;

  besARGUMENTS("r")
    &f
  besARGEND
  besLEFTVALUE(besARGUMENT(2),e);
 
  besRETURN_DOUBLE(gsl_frexp(f, *e));
besEND

Calling GSL SB extension module functions:

log1p()

Code: [Select]
DECLARE SUB log1p ALIAS "_log1p" LIB "gsl"

PRINT FORMAT("%.32g", log1p(34.0)),"\n"

3.5553480614894135136694330867613

frexp()

Code: [Select]
DECLARE SUB frexp ALIAS "_frexp" LIB "gsl"

x = 16.4
e = 0
fraction = frexp(x, e)

PRINT FORMAT("%g",fraction),"\n"
PRINT e,"\n"

0.5125
5
Script BASIC Project Manager

support

  • Administrator
  • *****
  • Posts: 844
    • Script BASIC Open Source Project
Re: GNU Scientific Library (GSL)
« Reply #1 on: May 30, 2011, 12:11:36 AM »
I added the Small Integer Powers to the ScriptBasic GSL extension module.

Code: [Select]
/* Small integer powers */


besFUNCTION(_pow_int)
  double x;
  int n;

  besARGUMENTS("ri")
    &x,&n
  besARGEND 

  besRETURN_DOUBLE(gsl_pow_int(x, n));
besEND


besFUNCTION(_pow_uint)
  double x;
  unsigned int n;

  besARGUMENTS("ri")
    &x,&n
  besARGEND 

  besRETURN_DOUBLE(gsl_pow_uint(x, n));
besEND


besFUNCTION(_pow_2)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_pow_2(x));
besEND


besFUNCTION(_pow_3)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_pow_3(x));
besEND


besFUNCTION(_pow_4)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_pow_4(x));
besEND


besFUNCTION(_pow_5)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_pow_5(x));
besEND


besFUNCTION(_pow_6)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_pow_6(x));
besEND


besFUNCTION(_pow_7)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_pow_7(x));
besEND


besFUNCTION(_pow_8)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_pow_8(x));
besEND


besFUNCTION(_pow_9)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_pow_9(x));
besEND

Code: [Select]
DECLARE SUB pow_4 ALIAS "_pow_4" LIB "gsl"

PRINT FORMAT ("%.16g",pow_4(3.141)),"\n"

97.335607906161
Script BASIC Project Manager

support

  • Administrator
  • *****
  • Posts: 844
    • Script BASIC Open Source Project
Re: GNU Scientific Library (GSL)
« Reply #2 on: June 01, 2011, 10:56:23 PM »
This is a beta version of the GSL Mathematical Functions portion of the library. I have attached the 32 and 64 bit version for Linux if you would like to try it out. I plan to create a gsl.bas module include file when the library has been fully implemented in ScriptBasic.

Code: [Select]
/*
   GNU Scientific Library
   Based on GSL 1.15
   Interface By: John Spikowski
   Refinements By: Armando I. Rivera (AIR)
   Version 0.01
*/

#include <stdio.h>
#include "../../basext.h"
#include <gsl/gsl_math.h>
     
besVERSION_NEGOTIATE
    return (int)INTERFACE_VERSION;
besEND

besSUB_START

besEND

besSUB_FINISH

besEND

/* Elementary Functions */

besFUNCTION(_log1p)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_log1p(x));
besEND


besFUNCTION(_expm1)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_expm1(x));
besEND


besFUNCTION(_hypot)
  double x,y;

  besARGUMENTS("rr")
    &x,&y
  besARGEND 

  besRETURN_DOUBLE(gsl_hypot(x, y));
besEND


besFUNCTION(_hypot3)
  double x,y,z;
 
  besARGUMENTS("rrr")
    &x,&y,&z
  besARGEND 

  besRETURN_DOUBLE(gsl_hypot3(x, y, z));
besEND


besFUNCTION(_acosh)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_acosh(x));
besEND


besFUNCTION(_asinh)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_asinh(x));
besEND


besFUNCTION(_atanh)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_atanh(x));
besEND


besFUNCTION(_ldexp)
  double x;
  int y;

  besARGUMENTS("ri")
    &x,&y
  besARGEND 

  besRETURN_DOUBLE(gsl_ldexp(x, y));
besEND


besFUNCTION(_frexp)
  double f;
  LEFTVALUE e;

  besARGUMENTS("r")
    &f
  besARGEND
  besLEFTVALUE(besARGUMENT(2),e);
 
  besRETURN_DOUBLE(gsl_frexp(f, *e));
besEND


/* Small integer powers */


besFUNCTION(_pow_int)
  double x;
  int n;

  besARGUMENTS("ri")
    &x,&n
  besARGEND 

  besRETURN_DOUBLE(gsl_pow_int(x, n));
besEND


besFUNCTION(_pow_uint)
  double x;
  unsigned int n;

  besARGUMENTS("ri")
    &x,&n
  besARGEND 

  besRETURN_DOUBLE(gsl_pow_uint(x, n));
besEND


besFUNCTION(_pow_2)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_pow_2(x));
besEND


besFUNCTION(_pow_3)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_pow_3(x));
besEND


besFUNCTION(_pow_4)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_pow_4(x));
besEND


besFUNCTION(_pow_5)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_pow_5(x));
besEND


besFUNCTION(_pow_6)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_pow_6(x));
besEND


besFUNCTION(_pow_7)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_pow_7(x));
besEND


besFUNCTION(_pow_8)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_pow_8(x));
besEND


besFUNCTION(_pow_9)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_DOUBLE(gsl_pow_9(x));
besEND


/* Testing the Sign of Numbers */


besFUNCTION(_SIGN)
  double x;

  besARGUMENTS("r")
    &x
  besARGEND 

  besRETURN_LONG(GSL_SIGN(x));
besEND


/* Testing for Odd and Even Numbers */


besFUNCTION(_IS_ODD)
  int x;

  besARGUMENTS("i")
    &x
  besARGEND 

  besRETURN_LONG(GSL_IS_ODD(x));
besEND


besFUNCTION(_IS_EVEN)
  int x;

  besARGUMENTS("i")
    &x
  besARGEND 

  besRETURN_LONG(GSL_IS_EVEN(x));
besEND


/* Maximum and Minimum functions */


besFUNCTION(_MIN)
  double a,b;

  besARGUMENTS("rr")
    &a,&b
  besARGEND 

  besRETURN_DOUBLE(GSL_MIN(a, b));
besEND


besFUNCTION(_MAX)
  double a,b;

  besARGUMENTS("rr")
    &a,&b
  besARGEND 

  besRETURN_DOUBLE(GSL_MAX(a, b));
besEND


besFUNCTION(_MIN_DBL)
  double a,b;

  besARGUMENTS("rr")
    &a,&b
  besARGEND 

  besRETURN_DOUBLE(GSL_MIN_DBL(a, b));
besEND


besFUNCTION(_MAX_DBL)
  double a,b;

  besARGUMENTS("rr")
    &a,&b
  besARGEND 

  besRETURN_DOUBLE(GSL_MAX_DBL(a, b));
besEND


besFUNCTION(_MIN_INT)
  long a,b;

  besARGUMENTS("ii")
    &a,&b
  besARGEND 
  besRETURN_LONG(GSL_MIN_INT(a,b));
besEND


besFUNCTION(_MAX_INT)
  long a,b;

  besARGUMENTS("ii")
    &a,&b
  besARGEND 

  besRETURN_LONG(GSL_MAX_INT(a, b));
besEND


besFUNCTION(_MIN_LDBL)
  double a,b;

  besARGUMENTS("rr")
    &a,&b
  besARGEND 

  besRETURN_DOUBLE(GSL_MIN_LDBL((long double)a, (long double)b));
besEND


besFUNCTION(_MAX_LDBL)
  double a,b;

  besARGUMENTS("rr")
    &a,&b
  besARGEND 

  besRETURN_DOUBLE(GSL_MAX_LDBL((long double)a, (long double)b));
besEND


/* Approximate Comparison of Floating Point Numbers */


besFUNCTION(_fcmp)
  double x,y,epsilon;
 
  besARGUMENTS("rrr")
    &x,&y,&epsilon
  besARGEND 

  besRETURN_LONG(gsl_fcmp(x, y, epsilon));
besEND


Script BASIC Project Manager

GSAC3

  • Newbie
  • *
  • Posts: 23
Re: GNU Scientific Library (GSL)
« Reply #3 on: October 21, 2014, 02:16:05 PM »
John: 

Do you have a WINDOWS-XT version of your GSL implementation for ScripyBasic 2.2 available?

Don

support

  • Administrator
  • *****
  • Posts: 844
    • Script BASIC Open Source Project
Re: GNU Scientific Library (GSL)
« Reply #4 on: October 21, 2014, 03:29:06 PM »
That was an early experiment. Feel free to expand on it if you like.
 
Script BASIC Project Manager