Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » [DISCUSSION] Add 'complex' datatype, to Value too
Re: [DISCUSSION] Add 'complex' datatype, to Value too [message #32970 is a reply to message #32961] Sun, 26 June 2011 16:05 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
ok this all doesnt help..we got a semantic problem here.

complex can be constructed both from double and anther complex.
same applies for operator=, it can assign a double or a complex.

now, for Value support (and Nuller) we have both operator double() and operator cdouble() implicit conversion, that applies here.

so the compiler could construct a cdouble from a Value (or Nuller) in 2 paths, converting it to double or cdouble. and it does not know which one to prefer.

cdouble x = val.operator double();
cdouble x = val.operator cdouble();

both work, same for Null.

thats due to the implicit handling of double as a sole real part in complex context in std::complex. so there is no way around that. not even deriving from std::complex, unless we spare out the complex(double) ctor and operator=(double).

and it only touches Value conversion stuff. one could leave out the Value support, but it's bad too. so at least to have the Value support like that (dealing with explicit conversion access in this special context) is an advantage, at least the user could know what to call if the compiler doesnt.

RESULT: though it's 'ugly' to explicitly call Null.operator cdouble() and v.operator cdouble(), it's a reasonable price to pay for a common std::complex usage which we dont need to code oursselves anymore. Nuller.operator cdouble() even could be left out, so it only would apply to Value.operator cdouble() to call. but i'd keep it the same semantic, Null.operator cdouble() as well.

is it worth it, that's the final question? everything else works..

[Updated on: Sun, 26 June 2011 16:21]

Report message to a moderator

Re: [DISCUSSION] Add 'complex' datatype, to Value too [message #32985 is a reply to message #32970] Mon, 27 June 2011 18:04 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I think it is possible that constructor from const Value& might improve the situation.
Re: [DISCUSSION] Add 'complex' datatype, to Value too [message #32991 is a reply to message #32985] Tue, 28 June 2011 09:04 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
do you mean explicit Value(const cdouble&) ?
Re: [DISCUSSION] Add 'complex' datatype, to Value too [message #32992 is a reply to message #32991] Tue, 28 June 2011 09:16 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
No, cdouble(const Value&).

See e.g. Color...

Not sure if that helps, but I guess it is worth of try...
Re: [DISCUSSION] Add 'complex' datatype, to Value too [message #32993 is a reply to message #32992] Tue, 28 June 2011 09:22 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
then the go is for deriving? i'll try.
Re: [DISCUSSION] Add 'complex' datatype, to Value too [message #33054 is a reply to message #32993] Tue, 05 July 2011 13:28 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
got sth workin.. i think it would do it. thanks for the hints..

attached are Complex.h and Complex.cpp for Core.
the attached patch is to include them properly...

cdouble is derived from std::complex. i wanted cdouble to have as little code as possible and use native external means, except for where not otherwise possible like Value conversion.

if this could go to Core, the posted plugin/kissfft (see above) is also possible..

test

void Test(const cdouble& c) { RLOG(c); }

CONSOLE_APP_MAIN
{
	cdouble y(1.,5.);
	cdouble x = 12;

	//cdouble handling
	double d = y.real();
	y+=3.;

	//cdouble to value conversion test
	Value v = RichToValue(y);
	v = y;
	int type = v.GetType();

	Vector<cdouble> vc;
	vc.Add(12);

	//Value to cdouble conversion test	
	x = v;

	//Null handling	
	Test(Null);
	x = Null;

	bool b;
	b = (v == x);
	b = (x == v);
	b = (v != x);
	b = (x != v);
}
  • Attachment: comp.svn.patch
    (Size: 0.95KB, Downloaded 192 times)
  • Attachment: Complex.h
    (Size: 1.24KB, Downloaded 218 times)
  • Attachment: Complex.cpp
    (Size: 0.30KB, Downloaded 464 times)

[Updated on: Tue, 05 July 2011 13:34]

Report message to a moderator

Re: [DISCUSSION] Add 'complex' datatype, to Value too [message #33087 is a reply to message #33054] Wed, 06 July 2011 13:17 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Tue, 05 July 2011 07:28

got sth workin.. i think it would do it. thanks for the hints..

attached are Complex.h and Complex.cpp for Core.
the attached patch is to include them properly...

cdouble is derived from std::complex. i wanted cdouble to have as little code as possible and use native external means, except for where not otherwise possible like Value conversion.

if this could go to Core, the posted plugin/kissfft (see above) is also possible..

test

void Test(const cdouble& c) { RLOG(c); }

CONSOLE_APP_MAIN
{
	cdouble y(1.,5.);
	cdouble x = 12;

	//cdouble handling
	double d = y.real();
	y+=3.;

	//cdouble to value conversion test
	Value v = RichToValue(y);
	v = y;
	int type = v.GetType();

	Vector<cdouble> vc;
	vc.Add(12);

	//Value to cdouble conversion test	
	x = v;

	//Null handling	
	Test(Null);
	x = Null;

	bool b;
	b = (v == x);
	b = (x == v);
	b = (v != x);
	b = (x != v);
}



Would you mind if instead of "cdouble" we use either complex or Complex?

I think integer complex numbers are unlikely and is we later decide to support 'float', we can still use something like complex32 or so...

Mirek
Re: [DISCUSSION] Add 'complex' datatype, to Value too [message #33091 is a reply to message #33087] Wed, 06 July 2011 14:48 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
i dont mind at all.. vote for Complex..complex would probably have issues with std::complex, where users do using namespace std
Re: [DISCUSSION] Add 'complex' datatype, to Value too [message #33093 is a reply to message #33091] Wed, 06 July 2011 17:25 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Thanks, with some minor changes applied.

One question: Should we consider polyequal for Complex vs double? (I mean, number+0i == number)

Or perhaps even type conversions where possible? As I see it, complex could be constructed from any number based Value as well, correct?

Mirek
Re: [DISCUSSION] Add 'complex' datatype, to Value too [message #33095 is a reply to message #33093] Wed, 06 July 2011 17:50 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
ofcorse...

to complex is probably semantically right.
i'd say: int/bool/double -> complex
what to do with complex -> *?
in case of i0 it's ok, but to raise exception or assert here could prove fatal Smile

cheers and thanks.

PS: what to do with kissfft plugin? will you upload it?
Re: [DISCUSSION] Add 'complex' datatype, to Value too [message #33096 is a reply to message #33095] Wed, 06 July 2011 19:02 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Wed, 06 July 2011 11:50

ofcorse...

to complex is probably semantically right.
i'd say: int/bool/double -> complex
what to do with complex -> *?
in case of i0 it's ok, but to raise exception or assert here could prove fatal Smile

cheers and thanks.

PS: what to do with kissfft plugin? will you upload it?


I think right now the right place is bazaar. I know it is potentially very usefull package, but by including it to uppsrc I would have to take certain level of responsibility about its maintainace, which I am right now not willing to do...

Mirek
Re: [DISCUSSION] Add 'complex' datatype, to Value too [message #33097 is a reply to message #33095] Wed, 06 July 2011 19:03 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Wed, 06 July 2011 11:50

ofcorse...

to complex is probably semantically right.
i'd say: int/bool/double -> complex
what to do with complex -> *?
in case of i0 it's ok, but to raise exception or assert here could prove fatal Smile



I think number->complex is fine and easy to do.

I think complex->number is both harder to implement and badly defined, so let us forget about this.

Mirek
Re: [DISCUSSION] Add 'complex' datatype, to Value too [message #33098 is a reply to message #33097] Wed, 06 July 2011 19:31 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Implemented and commited...
Re: [DISCUSSION] Add 'complex' datatype, to Value too [message #33100 is a reply to message #33098] Wed, 06 July 2011 21:48 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
thank you very much..
should i repost you the kissfft current state?
Re: [DISCUSSION] Add 'complex' datatype, to Value too [message #33101 is a reply to message #33095] Wed, 06 July 2011 22:19 Go to previous messageGo to next message
Zbych is currently offline  Zbych
Messages: 325
Registered: July 2009
Senior Member
kohait00 wrote on Wed, 06 July 2011 17:50


what to do with complex -> *?


I would suggest modulus (sqrt(r^2+i^2)) for doubles and ints.





Re: [DISCUSSION] Add 'complex' datatype, to Value too [message #33102 is a reply to message #33098] Wed, 06 July 2011 23:23 Go to previous messageGo to next message
unknown user
Hi,

Revision r3624 does not compile under g++, because Complex.h@14:
Complex(const Value& v) : C(IsNumber(v) ? C((double)v) : RichValue<Complex>::Extract(v)) {}

Error: no match for ternary 'operator?:'

Maybe RichValue<Complex>::Extract(v) should be cast to Complex?
Re: [DISCUSSION] Add 'complex' datatype, to Value too [message #33103 is a reply to message #33102] Wed, 06 July 2011 23:38 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
nope, Extract already returns Complex, but the ternary expects same type in first part as well..

change C to Complex:
Complex.h:14
	Complex(const Value& v) : C(IsNumber(v) ? Complex((double)v) : RichValue<Complex>::Extract(v)) {}


BTW: nice idea with modulus. is it mathematically semantically well placed?

EDIT: i adjusted kissfft, here comes the package for plugin. if it's ok for you...
  • Attachment: kissfft.rar
    (Size: 26.24KB, Downloaded 220 times)

[Updated on: Wed, 06 July 2011 23:55]

Report message to a moderator

Re: [DISCUSSION] Add 'complex' datatype, to Value too [message #33106 is a reply to message #33101] Thu, 07 July 2011 08:19 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Zbych wrote on Wed, 06 July 2011 16:19

kohait00 wrote on Wed, 06 July 2011 17:50


what to do with complex -> *?


I would suggest modulus (sqrt(r^2+i^2)) for doubles and ints.




I do not think it is a good idea. While there are situations where this is required, it should not happen behind the scene.

It is alike performing "abs" for int -> unsigned conversion... Smile
Re: [DISCUSSION] Add 'complex' datatype, to Value too [message #33107 is a reply to message #33106] Thu, 07 July 2011 08:23 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
i see in this case one-way conversion as the better strategy, just as in real world, the transition to complex world is one-way..
Re: [DISCUSSION] Add 'complex' datatype, to Value too [message #33115 is a reply to message #33107] Thu, 07 July 2011 17:40 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Thu, 07 July 2011 02:23

i see in this case one-way conversion as the better strategy, just as in real world, the transition to complex world is one-way..


Then we are finished now with complex, right?

Good job, kohait Smile

Mirek
Previous Topic: Bugs in Tuple, RemoveSorted and in Scribble Example
Next Topic: PLATFORM_X11 warnings
Goto Forum:
  


Current Time: Fri Mar 29 15:13:16 CET 2024

Total time taken to generate the page: 0.01227 seconds