Page 1 of 4

Maths Library

Posted: Fri Nov 14, 2008 10:39 am
by sospel
Hello !

Since my post on mathematical functions ( http://www.purebasic.fr/english/viewtop ... highlight= )
did not still receive concrete answer this day, I looked for a library of maths functions and I found this one: "APM" on the PureBasic site: http://www.purearea.net/pb/english/userlibs.php

As recommended at the end of the list of libraries, I put it into the directory: PureBasic\PureLibraries\UserLibraries\.
But, when I want to open it, PureBasic do not find it.

My test :

OpenConsole()
H_Lib = OpenLibrary(#PB_Any, "PbAPM")
PrintN (" ==> H_Lib = "+Str(H_Lib))
Input()

--------------------------------
Result : ==> H_Lib = 0 :cry:
--------------------------------

Where is the error?
Thank you in advance for your help !!
Cordially
SosPel

Posted: Fri Nov 14, 2008 10:41 am
by srod
You don't use OpenLibrary() on a Purebasic userlibrary.

Simply place the user library in the relevant PB folder and then restart the compiler/ide. From this point you can (if you installed everything okay) simply use the commands in the library as if they were regular PB commands.

I would say that it is unlikely that this library will work because it was written for an earlier version of Purebasic and so if the author has not updated the library.......

maths library

Posted: Fri Nov 14, 2008 11:16 am
by sospel
Thanks srod ! I' ll search another library, updated to 4.2 version !!

Posted: Fri Nov 14, 2008 12:46 pm
by Thalius
Worst case you still can use APM ( wrap a dll compile in 4.20 ) then open the dll in 4.30 - had to do such a thing myself on a userlib i used without source.
Its a bit cluttery but heck - if it saves me time and does the job. ;)

Cheers,
Thalius

Posted: Mon Apr 13, 2009 6:29 pm
by Arctic Fox
Excuse me for drawing attention to this subject again, but I am interested in pbAPM, too :lol:
Thalius wrote:Worst case you still can use APM ( wrap a dll compile in 4.20 ) then open the dll in 4.30 - had to do such a thing myself on a userlib i used without source.
It sounds like an ingenious trick, though I think pbAPM only works with PureBasic 3.90 and older, when PureBasic used the LCC linker.
Unfortunately for me I don't have PB 3.90 :cry:

Am I requesting too much when asking someone with PB 3.90 to do me a favour and compile a dll-wrap of pbAPM and upload it? :)
Or is it possible that the PureBasic Team will make PB 3.90 available in the Download Section? That would be very great! :D

Thanks in advance

Posted: Tue Apr 14, 2009 1:02 am
by jack
you can use the C static lib, just use Import.

Code: Select all

Structure  mapm
	*m_apm_data.c
	m_apm_id.l
	m_apm_refcount.l
	m_apm_malloclength.l
	m_apm_datalength.l
	m_apm_exponent.l
	m_apm_sign.l
EndStructure

ImportC "libc.lib"
; needed for the following symbols
;  __mb_cur_max.l
;  _pctype
EndImport 

ImportC "mapm.lib"
	*MM_Zero
	*MM_One
	*MM_Two
	*MM_Three
	*MM_Four
	*MM_Five
	*MM_Ten

	*MM_PI
	*MM_HALF_PI
	*MM_2_PI
	*MM_E

	*MM_LOG_E_BASE_10
	*MM_LOG_10_BASE_E
	*MM_LOG_2_BASE_E
	*MM_LOG_3_BASE_E

  m_apm_init()
  m_apm_free(*n.mapm)
  m_apm_free_all_mem()
  m_apm_trim_mem_usage()
  m_apm_set_string(*n.mapm,sn.s)
  m_apm_set_long(*mp.mapm, long.l)
  m_apm_set_double(*mp.mapm, dbl.d)
  m_apm_to_string(buffer.s, dplaces.l, *n.mapm)
  m_apm_to_fixpt_string(buffer.s, dplaces.l, *n.mapm)
  m_apm_to_fixpt_stringex(buffer.s, dplaces.l, *n.mapm, radix.c, separator_char.c, separator_count.l)
;  example use  
;  m_apm_to_fixpt_stringex(s,20,*m,'.',',',5)
  m_apm_to_fixpt_stringexp(dplaces.l, *n.mapm, radix.c, separator_char.c, separator_count.l)
;  example use 
;  al.l=m_apm_to_fixpt_stringexp(100,*m,'.',',',5)
;  s=PeekS(al)
;  FreeMemory(al)
  m_apm_to_integer_string(buffer.s, *n.mapm)
  m_apm_absolute_value(*r.mapm, *n.mapm)
  m_apm_negate(*r.mapm, *n.mapm)
  m_apm_copy(*r.mapm, *n.mapm)
  m_apm_round(*r.mapm, decimal_places.l, *n.mapm)
  
	m_apm_compare.l(*x.mapm, *y.mapm)
	m_apm_sign.l(*x.mapm)
	m_apm_exponent.l(*x.mapm)
	m_apm_significant_digits.l(*x.mapm)
	m_apm_is_integer.l(*x.mapm)
	m_apm_is_even.l(*x.mapm)
	m_apm_is_odd.l(*x.mapm)

	m_apm_gcd(*result.mapm, *x.mapm, *y.mapm)
	m_apm_lcm(*result.mapm, *x.mapm, *y.mapm)

	m_apm_add(*result.mapm, *x.mapm, *y.mapm)
	m_apm_subtract(*result.mapm, *x.mapm, *y.mapm)
	m_apm_multiply(*result.mapm, *x.mapm, *y.mapm)
	m_apm_divide(*result.mapm, dplaces.l, *x.mapm, *y.mapm)
	m_apm_integer_divide(*result.mapm, *x.mapm, *y.mapm)
	m_apm_integer_div_rem(*quot.mapm, *rem.mapm, *x.mapm, *y.mapm)
	m_apm_reciprocal(*result.mapm, dplaces.l, *x.mapm)
	m_apm_factorial(*result.mapm, *x.mapm)
	m_apm_floor(*result.mapm, *x.mapm)
	m_apm_ceil(*result.mapm, *x.mapm)
	m_apm_get_random(*result.mapm)
	m_apm_set_random_seed(s.s)

	m_apm_sqrt(*result.mapm, dplaces.l, *x.mapm)
	m_apm_cbrt(*result.mapm, dplaces.l, *x.mapm)
	m_apm_log(*result.mapm, dplaces.l, *x.mapm)
	m_apm_log10(*result.mapm, dplaces.l, *x.mapm)
	m_apm_exp(*result.mapm, dplaces.l, *x.mapm)
	m_apm_pow(*result.mapm, dplaces.l, *x.mapm, *y.mapm)
	m_apm_integer_pow(*result.mapm, dplaces.l, *x.mapm, y.l)
	m_apm_integer_pow_nr(*result.mapm, *x.mapm, y.l)

	m_apm_sin_cos(*sin.mapm, *cos.mapm, dplaces.l, *x.mapm)
	m_apm_sin(*result.mapm, dplaces.l, *x.mapm)
	m_apm_cos(*result.mapm, dplaces.l, *x.mapm)
	m_apm_tan(*result.mapm, dplaces.l, *x.mapm)
	m_apm_arcsin(*result.mapm, dplaces.l, *x.mapm)
	m_apm_arccos(*result.mapm, dplaces.l, *x.mapm)
	m_apm_arctan(*result.mapm, dplaces.l, *x.mapm)
	m_apm_arctan2(*result.mapm, dplaces.l, *x.mapm, *y.mapm)

	m_apm_sinh(*result.mapm, dplaces.l, *x.mapm)
	m_apm_cosh(*result.mapm, dplaces.l, *x.mapm)
	m_apm_tanh(*result.mapm, dplaces.l, *x.mapm)
	m_apm_arcsinh(*result.mapm, dplaces.l, *x.mapm)
	m_apm_arccosh(*result.mapm, dplaces.l, *x.mapm)
	m_apm_arctanh(*result.mapm, dplaces.l, *x.mapm)
  
EndImport

OpenConsole()

*n.mapm
*m.mapm
*k.mapm
*n=m_apm_init()
*m=m_apm_init()
*k=m_apm_init()
s.s

;examples to assign values to an mp number

;m_apm_set_string(*n,"1") ;from string
;m_apm_set_long(*n,123)   ;from long
;m_apm_set_double(*n,3.0) ;from double
;m_apm_copy(*m,*n)        ;copy n to m

PrintN("Factorial of 20")
m_apm_set_long(*n,20)
m_apm_factorial(*k, *n)

al.l=m_apm_to_fixpt_stringexp(10,*k,'.',',',5)
s=PeekS(al)
FreeMemory(al) ;free the memory
PrintN(s)

;-- another way
s=Space(512) ;make sure there's enough memory allocated for convertion to string
m_apm_to_integer_string(s,*k)
PrintN(s)

;-- yet another way
s=Space(512)
m_apm_to_fixpt_stringex(s, 20, *k, '.', ',', 5)
PrintN(s)

;-- one more way
s=Space(512)
m_apm_to_string(s, 20, *k)
PrintN(s)

Print("Press RETURN to end ")
Input()

m_apm_free(*k)
m_apm_free(*m)
m_apm_free(*n)
CloseConsole()

Posted: Tue Apr 14, 2009 2:30 pm
by Arctic Fox
Thanks a lot jack for your reply, but where do I find these static libraries?

Posted: Tue Apr 14, 2009 4:13 pm
by jack
it's best if you build the lib yourself, less chance of using malware.
you find the source here http://www.tc.umn.edu/~ringx004/mapm-main.html
the source includes batch files for a number of C compilers, just run the appropiate batch file.

Posted: Tue Apr 14, 2009 5:12 pm
by Peyman
jack wrote:you can use the C static lib, just use Import.

Code: Select all

ImportC "libc.lib"
; needed for the following symbols
;  __mb_cur_max.l
;  _pctype
EndImport 
hi jack, how can i find this lib for purebasic ?
i have problem with __mb_cur_max and __pctype

Posted: Tue Apr 14, 2009 6:07 pm
by jack
I just copied the one from vc6 to the pb windows library, but I will see if I can find another solution.

Posted: Tue Apr 14, 2009 7:01 pm
by jack
try this, in the file M_APM.H add this two lines and recompile.

Code: Select all

int __mb_cur_max;
unsigned short* _pctype;
not sure it's the best way to solve this problem, I will search some more.

Posted: Tue Apr 14, 2009 8:11 pm
by Arctic Fox
jack wrote:the source includes batch files for a number of C compilers, just run the appropiate batch file.
Do you know a good free C compiler, which works? I can't get DMC to work :(

Posted: Tue Apr 14, 2009 9:36 pm
by milan1612
Arctic Fox wrote:
jack wrote:the source includes batch files for a number of C compilers, just run the appropiate batch file.
Do you know a good free C compiler, which works? I can't get DMC to work :(
Try PellesC, it's free, standard's compliant and uses the same linker as
Purebasic (that minimizes the risk of binary incompatibilities).

Posted: Tue Apr 14, 2009 9:36 pm
by jack
dmc outputs libraries in omf format which is not compatible with PB, I recommend mingw32 http://sourceforge.net/project/showfile ... _id=240780

[edit] compiled with mingw and there were no problems with unresolved symbols, gcc outputs libs with "a" extention, just change to lib and it works.
[/edit]

Posted: Tue Apr 14, 2009 9:56 pm
by Arctic Fox
Thanks for the replies, I'll give it a try :o