decQuad lib and example

Post your FreeBASIC tips and tricks here. Please don’t post your code without including an explanation.
srvaldez
Posts: 2640
Joined: Sep 25, 2005 21:54

decQuad lib and example

Postby srvaldez » Jun 10, 2016 21:02

every now and then the need for a decimal type might come in handy, so I compiled the decQuad part of decNumber and translated the appropriate headers with fbfrog.
I also added dodicat's trig functions.
here's decQuad-Linux
Last edited by srvaldez on Jun 13, 2016 21:03, edited 2 times in total.
St_W
Posts: 1514
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: decQuad lib and example

Postby St_W » Jun 11, 2016 17:18

Could you provide instructions how to build the static libraries, which you do provide only as binaries?

e.g.:
source: http://download.icu-project.org/files/d ... cu-368.zip
create library with:
gcc -c decQuad.c decContext.c
ar rcs libdecQuad.a decQuad.o decContext.o
dodicat
Posts: 6799
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: decQuad lib and example

Postby dodicat » Jun 12, 2016 21:01

Thanks srvaldez.
I had to re-arrange the folders a bit.
The files in the decnumber folder could not be reached from the example folder (32 bit)
I tested with:
print qdecimal_acos("-1")
And, sure enough, I got a big Pi.
srvaldez
Posts: 2640
Joined: Sep 25, 2005 21:54

Re: decQuad lib and example

Postby srvaldez » Jun 13, 2016 17:33

updated the overload includes and examples.
jdmcbride
Posts: 27
Joined: Aug 06, 2016 16:13

Re: decQuad lib and example

Postby jdmcbride » Sep 10, 2016 21:37

Hi srvaldez,

Would you happen to have some basic sources that show how to do simple match functions using decQuad?
srvaldez
Posts: 2640
Joined: Sep 25, 2005 21:54

Re: decQuad lib and example

Postby srvaldez » Sep 11, 2016 2:34

hello jdmcbride
I am not familiar with the match function, is this what you mean?
The MATCH function searches for a specified item in a range of cells, and then returns the relative position of that item in the range. For example, if the range A1:A3 contains the values 5, 25, and 38, then the formula =MATCH(25,A1:A3,0) returns the number 2, because 25 is the second item in the range.


a rough example might be

Code: Select all

#include "decNumber\decQuadMathOverload.bi"

function match(byval n as qdecimal, a() as qdecimal) as integer
    dim as integer i
    For i=lbound(a) to ubound(a)
        if a(i)=n then return i
    next
    return 0
end function

Dim As qdecimal num=25, a(1 to 3)={5, 25, 38}

print match(num, a())
sleep
jdmcbride
Posts: 27
Joined: Aug 06, 2016 16:13

Re: decQuad lib and example

Postby jdmcbride » Sep 11, 2016 2:55

srvaldez,

Please forgive me. I am advanced in years and between poor eyesight and fat fingers, I can really muck things up.

I meant simple "math" examples.

Actually, I've had a great deal of success with this on my own. Only one I havent ironed out is how to handle the remainder after division.

My project is a base10 to base36 encoder/decoder. However, getting it to handle large, out to 20 or 30 decimal places has been problematic. I'm sure decQuad is the answer, when I figure it out.

it would be wonderfully easy, if FB had greater precision than it has. Maybe a future version will make that possible.

Have a good night sir.
jdmcbride
Posts: 27
Joined: Aug 06, 2016 16:13

Re: decQuad lib and example

Postby jdmcbride » Sep 11, 2016 2:57

Since I here... is there an easy way to to separate a big float into a whole number and remainder?
srvaldez
Posts: 2640
Joined: Sep 25, 2005 21:54

Re: decQuad lib and example

Postby srvaldez » Sep 11, 2016 3:12

it's close to my bedtime but have a look at the following functions
decQuadReduce, decQuadRemainder, decQuadRemainderNear also look at the pdf file that was included.
D.J.Peters
Posts: 8208
Joined: May 28, 2005 3:28
Contact:

Re: decQuad lib and example

Postby D.J.Peters » Sep 11, 2016 3:41

Tips and Tricks are the wrong section for 'decQuad' it's for source code only
why not using the forum Libraries sextion ?

Joshy
jdmcbride
Posts: 27
Joined: Aug 06, 2016 16:13

Re: decQuad lib and example

Postby jdmcbride » Sep 11, 2016 3:59

Sure. How to move?
srvaldez
Posts: 2640
Joined: Sep 25, 2005 21:54

Re: decQuad lib and example

Postby srvaldez » Sep 11, 2016 12:44

@jdmcbride
from what you wrote, I think that decQuad may not be your best option, if you only need Big Integers then maybe the wrapper for gmp integer type by yetifoot may suit you viewtopic.php?f=7&t=7173
srvaldez
Posts: 2640
Joined: Sep 25, 2005 21:54

Re: decQuad lib and example

Postby srvaldez » Sep 11, 2016 15:35

@jdmcbride
I find no elegant way to get the integer and fractional parts but you can do it the dirty way, you could write a sub or function.

Code: Select all

#include "decNumber\decQuadMathOverload.bi"

dim as qdecimal x="314.1592653"
dim as long fr
dim as string s
s=x.toString
fr=instr(s,".")
print left(s,fr-1),mid(s,fr)
sleep
jdmcbride
Posts: 27
Joined: Aug 06, 2016 16:13

Re: decQuad lib and example

Postby jdmcbride » Sep 12, 2016 0:43

Hi srvaldez,

Yes, you are correct. I had no luck ether and have resorted to hacking the data as a string. Thank you, so much, for your help.

Jerry

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 6 guests