NO

Author Topic: Fork of QD (2.3.17) dll  (Read 1167 times)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1633
Re: Fork of QD (2.3.17) dd to C
« Reply #15 on: August 27, 2017, 08:38:53 am »
Those missing files are added to zip.
That c_dd_error was a user function as dll needs message for GUI too.
c_dd_dll.c have MessageBox version for that.
c_dd_error.c should use fputs(msg, stderr); later.

Now is time to test and fix functions.
WARNING: not a good project with PellesC, too much difficulties.

C# test
Code: [Select]
using System;
using System.Runtime.InteropServices;

public class TestDllCs
{
[DllImport("c_dd.dll")]
static extern void c_dd_copy_d(double d, double [] dd);
[DllImport("c_dd.dll")]
static extern void c_dd_write(double [] dd);

public static void Main(string[] args) {
double [] dd = new double [2];
c_dd_copy_d(1.0, dd);
c_dd_write(dd);
}
}
EDIT 2017-08-28: c_dd_dll_ms.zip missing dd_real_ constants. Compiled with msvc 19.10, linked with msvcr100.dll
EDIT 2017-08-31: fix for sin / cos / tan functions.
« Last Edit: September 08, 2017, 01:51:32 pm by TimoVJL »
May the source be with you

Offline jack

  • Member
  • *
  • Posts: 59
Re: Fork of QD (2.3.17) dll
« Reply #16 on: August 27, 2017, 12:35:03 pm »
thank you

Offline jack

  • Member
  • *
  • Posts: 59
Re: Fork of QD (2.3.17) dll
« Reply #17 on: August 29, 2017, 06:56:27 pm »
hello TimoVJL
I tested c_dd_dll_ms and here's what I found
c_dd_add   ok
c_dd_sub   ok
c_dd_mul   ok
c_dd_div   ok
c_dd_sqr   ok
c_dd_sqrt   ok
c_dd_write   ok
c_dd_read   ok
the trig, log and exp functions give wrong results, c_dd_atan gives right result only for arg=1, c_dd_tan is missing.
sorry for the bad report, I just thought that you might like to have some feedback. :)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1633
Re: Fork of QD (2.3.17) dd to C
« Reply #18 on: August 29, 2017, 07:03:46 pm »
Thanks.

I can't even print PI correctly with PellesC, even same code worked with msvc 19.10 and msvcr100.dll.
Trigonometric functions fails in my tests too.
PellesC have a double last bit problem?

In c_dd_internal.h this was not defined:
QD_API void QD_CALL c_dd_tan(const dd_real *a, dd_real *ret);

Anyone with msvc skills to take over this project?

msvc
Quote
31415926535897932384626433832795
3.1415926535897931   0.0000000000000001
pocc
Quote
31415926535897932384626433832795
3.1415926535897936   0.0000000000000001
« Last Edit: September 07, 2017, 11:40:51 am by TimoVJL »
May the source be with you

Offline jack

  • Member
  • *
  • Posts: 59
Re: Fork of QD (2.3.17) dll
« Reply #19 on: August 29, 2017, 08:49:35 pm »
hello TimoVJL
I didn't think about this earlier, but this type of arithmetic is sensitive to the FPU setting, remember that in the original code there were two functions to set the FPU flags, I bet that's where the problem is, or if you can coerce the compiler to use sse2 instructions then you should be ok.
« Last Edit: August 29, 2017, 08:54:19 pm by jack »

Offline jj2007

  • Member
  • *
  • Posts: 466
Re: Fork of QD (2.3.17) dll
« Reply #20 on: August 30, 2017, 05:26:48 pm »
this type of arithmetic is sensitive to the FPU setting, remember that in the original code there were two functions to set the FPU flags, I bet that's where the problem is, or if you can coerce the compiler to use sse2 instructions then you should be ok.

But don't forget LDMXCSR ;)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1633
Re: Fork of QD (2.3.17) dd to C
« Reply #21 on: August 30, 2017, 05:36:42 pm »
If the problem is in crt and pocc use that crt, i can't see how to fix that last bit problem ???

BTW: msvc have it's own jokes:
Code: [Select]
#define NAN        (0.0 / (1.0, 0.0))
const dd_real dd_real_nan = {NAN, NAN};
Quote
dd_real_nan.c(4): error C2099: initializer is not a constant
and even with this:
Code: [Select]
const dd_real dd_real_nan = {(0.0 / (1.0, 0.0)), (0.0 / (1.0, 0.0))};I just don't know how tell to cl.exe about the current wind direction :-\

EDIT: constants needs fixing for PellesC:( Done.
« Last Edit: September 05, 2017, 12:01:01 pm by TimoVJL »
May the source be with you

Offline jack

  • Member
  • *
  • Posts: 59
Re: Fork of QD (2.3.17) dll
« Reply #22 on: September 05, 2017, 01:47:22 pm »
hello TimoVJL
you are getting close, however there's a bug in dd_to_digits, if dd_variable.x[0] = 0.1 and dd_variable.x[1] = -5.551115123125983e-018 then you get an error and crash.
Quote
(dd_to_digits): can't compute exponent.
the trigs seem to be ok, but only made a very simple test.
« Last Edit: September 05, 2017, 01:50:02 pm by jack »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1633
Re: Fork of QD (2.3.17) dd to C
« Reply #23 on: September 05, 2017, 03:47:33 pm »
Thanks.

fixed in a10.
it was just a stupid comparison error.
« Last Edit: September 05, 2017, 03:52:26 pm by TimoVJL »
May the source be with you

Offline jack

  • Member
  • *
  • Posts: 59
Re: Fork of QD (2.3.17) dll
« Reply #24 on: September 05, 2017, 04:41:07 pm »
there's a problem with dd_cos, if dd_x = 1/n , n=11, 12, 13 ... then dd_cos fails, for dd_x=1/11 the result is
Quote
                                   dd_x.x[0]                               dd_x[1]
cos(1/11)            0.9958706137005629          0.9958706137005629
it should be something like
Quote
cos(1/11)            0.9958706137005629         -4.772639498746044e-017
[edit] dd_log is not working
« Last Edit: September 05, 2017, 05:04:44 pm by jack »

Offline jack

  • Member
  • *
  • Posts: 59
Re: Fork of QD (2.3.17) dll
« Reply #25 on: September 05, 2017, 07:57:36 pm »
I did a loop from -70 to 70 and used mpfr for verification, for log/exp the loop was from 1 to 70
sin, cos, tan, atan, log and exp are ok, not sure about the hyperbolic functions.

Offline jack

  • Member
  • *
  • Posts: 59
Re: Fork of QD (2.3.17) dll
« Reply #26 on: September 05, 2017, 08:10:05 pm »
dd_atanh(dd_tanh(x)) from 1 to 19 ok, above 19 dd_atanh says "Argument out of domain."

Offline jack

  • Member
  • *
  • Posts: 59
Re: Fork of QD (2.3.17) dll
« Reply #27 on: September 05, 2017, 09:13:35 pm »
we really need a good test suite to check the functions in the supported range, the hyperbolic functions are trickier to check.

Offline jack

  • Member
  • *
  • Posts: 59
Re: Fork of QD (2.3.17) dll
« Reply #28 on: September 06, 2017, 12:11:46 am »
I made a small test and the trigs -not including hyperbolic- , log and exp seem to be ok
I have been doing my testing in freebasic because I am more familiar with it than C.