PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 6 7 [8] 9 10 ... 15

Author Topic: CWindow Release Candidate 31  (Read 5821 times)

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2785
    • Josť Roca Software
Re: CWindow Release Candidate 31
« Reply #105 on: September 08, 2017, 11:35:57 PM »

With PowerBASIC the parameter is optional and a NULL is also being passed. The returned message does not make sense to me. It is not even listed in the list of possible errors in the MSDN documentation for the CreateDomain method.

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2785
    • Josť Roca Software
Re: CWindow Release Candidate 31
« Reply #106 on: September 08, 2017, 11:53:12 PM »

And CreateDomainEx also fails with the same error. These are the only two that have an string parameter in this interface, so it is my main suspect.

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2785
    • Josť Roca Software
Re: CWindow Release Candidate 31
« Reply #107 on: September 09, 2017, 12:18:46 AM »

I also have tried

Code: [Select]
   DIM ppEvidence AS IUnknown PTR
   m_pCorRuntimeHost->CreateEvidence(@ppEvidence)
   DIM hr AS HRESULT = m_pCorRuntimeHost->CreateDomain(@wszFriendlyName, ppEvidence, cast(ANY PTR, @pUnk))

and also fails.

Looks like the string parameter is the problem, but I have also tried passing a BSTR and even a CWSTR and a ZSTRING and it fails. I don't understand why.

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8104
  • Windows 10
    • PlanetSquires Software
Re: CWindow Release Candidate 31
« Reply #108 on: September 11, 2017, 09:56:45 AM »

Have you been able to figure out the string problem? Problems like this must drive you crazy! :)  :)  :)
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2785
    • Josť Roca Software
Re: CWindow Release Candidate 31
« Reply #109 on: September 11, 2017, 10:19:59 AM »

No. I have tried everything and always get the same error. Yet similar code works with PowerBasic. Everything else works, so we can use it using the default domain. Custom domains aren't indispensable, just convenient for some tasks.

Some time ago I had a problem to add OpenGL support to the graphic control. Some months later, I tried again and it worked. I can't tell you where was the problem, because I had discarded the code and started from scratch.

Meanwhile, I have been working writing wrapper functions to support Complex numbers. Instead of a class, this time I have used plain functions and use the Afx namespace to avoid conflicts.

Code: [Select]
#include once "AfxComplex.inc"

DIM cpx1 AS _complex = (3, 4)
DIM cpx2 AS _complex = (5, 6)
cpx1 = cpx1 + cpx2
print Afx.Cstr(cpx1)

There are a lot of math functions, most of which I have already checked that return the right results. The most complex functions are an adaptation of the ones from the GSL - GNU Scientific Library, which unfortunately is LGPL.

« Last Edit: September 11, 2017, 12:54:24 PM by Josť Roca »
Logged

Johan Klassen

  • FireFly3 Registered User
  • Little Newbie FireFly
  • *
  • Posts: 19
  • FF3 User
Re: CWindow Release Candidate 31
« Reply #110 on: September 12, 2017, 10:03:55 AM »

hello Josť Roca
just in case you need to have a look at complex functions implementation there's this library http://www.wolfgang-ehrhardt.de/misc_en.html#damath
Quote
License

(C) Copyright 2002-2017 Wolfgang Ehrhardt

Copying Conditions

This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.

3. This notice may not be removed or altered from any source distribution.
Logged

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2785
    • Josť Roca Software
Re: CWindow Release Candidate 31
« Reply #111 on: September 12, 2017, 03:34:09 PM »

Thanks for the link. I already have implemented a big amount of functions and, more important, I have checked that all of them work correctly. Don't know if I will add more. Math is not my forte.
« Last Edit: September 12, 2017, 05:51:48 PM by Josť Roca »
Logged

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2785
    • Josť Roca Software
Re: CWindow Release Candidate 31
« Reply #112 on: September 14, 2017, 11:58:24 PM »

I'm replacing the GSL functions with translations of the .NET System.Numerics/System/Numerics/Complex.cs class (source code: https://github.com/Microsoft/referencesource/blob/master/System.Numerics/System/Numerics/Complex.cs ) and apparently the code for the Asin and Acos methods is reversed! I have checked results with GSL and from MATLAB examples, and Asin returns the expected results for Acos, and viceversa.

The reason of the replacement is because this .NET class as a MIT license, whereas GSL as a GPL license.

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2785
    • Josť Roca Software
Re: CWindow Release Candidate 31
« Reply #113 on: September 15, 2017, 01:42:41 AM »

And also differs in the sign of the imaginary part, + instead of - (according the other sources). Looks like they have got everything reversed. Anybody has the means to ascertain which source is right?

Code: [Select]
' ========================================================================================
' * Returns the complex arcsine of a complex number.
' The branch cuts are on the real axis, less than -1 and greater than 1.
' Example:
'   DIM z AS _complex = (1, 1)
'   z = AfxCArcSin(z)
'   PRINT AfxCStr(z)
' Output: 0.6662394324925152 +1.061275061905036 * i
' ========================================================================================
' ========================================================================================
' - NET 4.7 code:
' public static Complex Acos(Complex value) /* Arccos */
' { return (-ImaginaryOne) * Log(value + ImaginaryOne*Sqrt(One - (value * value))); }
' Note: Apparently, .NET has got the code for the Asin and Acos function revesed!
' It also returns -1.061275061905036 * i instead of +1.061275061905036 * i in the above example.
' ========================================================================================
PRIVATE FUNCTION AfxCArcSin (BYREF value AS _complex) AS _complex
   DIM ImaginaryOne AS _complex = TYPE<_complex>(0.0, 1.0)
   DIM One AS _complex = TYPE<_complex>(1.0, 0.0)
'   RETURN (-ImaginaryOne) * AfxCLog(value + ImaginaryOne * AfxCSqr(One - (value * value)))
   DIM z AS _complex = AfxCLog(value + ImaginaryOne * AfxCSqr(One - (value * value)))
   RETURN TYPE<_complex>(z.y, z.x)
END FUNCTION
' ========================================================================================

Code: [Select]
' ========================================================================================
' * Returns the complex arccosine of a complex number.
' The branch cuts are on the real axis, less than -1 and greater than 1.
' Example:
'   DIM z AS _complex = (1, 1)
'   z = AfxCArcCos(z)
'   print AfxCStr(z)
' Output: 0.9045568943023814 -1.061275061905036 * i
' ========================================================================================
' ========================================================================================
' - NET 4.7 code:
' public static Complex Asin(Complex value) /* Arcsin */
' { return (-ImaginaryOne) * Log(ImaginaryOne * value + Sqrt(One - value * value)); }
' Note: Apparently, .NET has got the code for the Asin and Acos function revesed!
' It also returns +1.061275061905036 * i instead of -1.061275061905036 * i in the above example.
' ========================================================================================
PRIVATE FUNCTION AfxCArcCos (BYREF value AS _complex) AS _complex
   DIM ImaginaryOne AS _complex = TYPE<_complex>(0.0, 1.0)
   DIM One AS _complex = TYPE<_complex>(1.0, 0.0)
'   RETURN (-ImaginaryOne) * AfxCLog(ImaginaryOne * value + AfxCSqr(One - value * value))
   DIM z AS _complex = AfxCLog(ImaginaryOne * value + AfxCSqr(One - value * value))
   RETURN TYPE<_complex>(z.y, z.x)
END FUNCTION
' ========================================================================================

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2785
    • Josť Roca Software
Re: CWindow Release Candidate 31
« Reply #114 on: September 15, 2017, 02:09:58 AM »

Another problem with the sign in the arctangent function.

Code: [Select]
' ========================================================================================
' * This function returns the complex arctangent of a complex number.
' The branch cuts are on the imaginary axis, below -i and above i.
' Example:
'   DIM z AS _complex = (1, 1)
'   z = AfxCArcTan(z)
'   PRINT AfxCStr(z)
' Output: 1.017221967897851 +0.4023594781085251 * i
' ========================================================================================
' ========================================================================================
' - NET 4.7 code:
' public static Complex Atan(Complex value) /* Arctan */
' {
'    Complex Two = new Complex(2.0, 0.0);
'    return (ImaginaryOne / Two) * (Log(One - ImaginaryOne * value) - Log(One + ImaginaryOne * value));
' }
' Note: It returns -0.4023594781085251 * i instead of +0.4023594781085251 * i, so I have
' needed to use a workaround.
' ========================================================================================
' ========================================================================================
PRIVATE FUNCTION AfxCArcTan (BYREF value AS _complex) AS _complex
   DIM ImaginaryOne AS _complex = TYPE<_complex>(0.0, 1.0)
   DIM One AS _complex = TYPE<_complex>(1.0, 0.0)
   DIM Two AS _complex = TYPE<_complex>(2.0, 0.0)
'   RETURN (ImaginaryOne / Two) * (AfxCLog(One - ImaginaryOne * value) - AfxCLog(One + ImaginaryOne * value))
   DIM z AS _complex = AfxCLog(One - ImaginaryOne * value) - AfxCLog(One + ImaginaryOne * value)
   z /= 2 : DIM temp AS DOUBLE = z.x : z.x = z.y : z.y = temp
   RETURN z
END FUNCTION
' ========================================================================================

Johan Klassen

  • FireFly3 Registered User
  • Little Newbie FireFly
  • *
  • Posts: 19
  • FF3 User
Re: CWindow Release Candidate 31
« Reply #115 on: September 15, 2017, 09:20:57 AM »

hello Josť Roca
I downloaded your AfxComplex and it agrees with pari/gp
however the functions in your last posts give wrong result, is AfxClog giving the right result?
note: I changed the call to AfxClog to Clog because AfxClog is not posted.
« Last Edit: September 15, 2017, 12:20:35 PM by Johan Klassen »
Logged

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2785
    • Josť Roca Software
Re: CWindow Release Candidate 31
« Reply #116 on: September 15, 2017, 01:36:19 PM »

Forget the previous code. I have fully reworked the module to get rid of the GSL code beause the GNU Scientific Library has a GPL license. Some of the new functions are based in code from Complex.cs class for .NET, that uses the more permissive MIT license. I also have changed the naming convention and removed the namespace to make the module fully independent of my framework (as soon as you use some open source code, you risk to "contaminate" all the rest of your code).

It seems to be working fine, although apparently the .NET code for Acos and Asin, that I have used in the AfxCArcSin and AfxCArcCos functions, seems to be reversed, so I have swaped it. These two functions and Atan (code used in AfxCArcTan) also return a wrong sign, so I have used a workaround.
« Last Edit: September 15, 2017, 03:38:45 PM by Josť Roca »
Logged

Johan Klassen

  • FireFly3 Registered User
  • Little Newbie FireFly
  • *
  • Posts: 19
  • FF3 User
Re: CWindow Release Candidate 31
« Reply #117 on: September 15, 2017, 02:43:22 PM »

there's a problem with AfxClog
Code: [Select]
dim as _complex y, x=(1,1)
y=AfxCexp(x)
y=AfxClog(y)
print y.x, y.y '-> 1             0.5707963267948967
I think the culprit is atan2, if you swap the arguments it seems to work, but then the other function are broke, perhaps this was the cause of your problems all along.
« Last Edit: September 15, 2017, 02:55:34 PM by Johan Klassen »
Logged

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2785
    • Josť Roca Software
Re: CWindow Release Candidate 31
« Reply #118 on: September 15, 2017, 03:15:06 PM »

Yes, AfxCLog is wrong. I will have to fix it and then recheck all the other functions that use it. I was surprised of such a "bug" in a .NET class and thought that I was missing something. Thanks very much for spotting it.

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2785
    • Josť Roca Software
Re: CWindow Release Candidate 31
« Reply #119 on: September 15, 2017, 03:45:13 PM »

> perhaps this was the cause of your problems all along.

Yes, that was it. It was I who was reversing the result, not the .NET class. It has been an easy fix because I had the original code remed just before the workaround code, so I only have needed to unrem it and remove the other code. I didn't notice the bug in AfxCLog because, unfortunately, with the values that I used to test it the result was right.

« Last Edit: September 15, 2017, 03:50:43 PM by Josť Roca »
Logged
Pages: 1 ... 6 7 [8] 9 10 ... 15