32-bit-floating point data type

Forums for specific tips, techniques and example code
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

32-bit-floating point data type

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:34 pm

by jadenews >> Tue, 3 Jul 2001 5:35:14 GMT

Hi,

An external function call requires a 32-bit floating point data type (float) which Jade does not implement. I'm passing therefore the value using a binary representation as Binary[4]. In order to get the correct float representation of the value I wrote a C++ library which takes the intended value as String and converts it into a Float representation. The following code snippet demonstrates this:

DLLExport float WINAPI ConvertJadeRealToFloat(char *jadeReal)

{

float converted;

int result;

int decimal, sign;

converted = (float)atof(jadeReal);

result = MessageBox(0,_fcvt(converted, 3, &decimal, &sign), "Conversion", 0);


return converted;

}

As far as I can tell the conversion returns the correct float representation. I defined the external function call in Jade as:

convertJadeRealToFloat(real:String):Binary[4] is ConvertJadeRealToFloat in dllbasic;

in the assumption that the library return value is "dumped" straight into the binary (which then would be passed to the external function requesting the 32-bit floating point.

However, using a Binary return value in the external function call always gives an error message (4038). But, using the Real return type gives the correct value (without crashing needless to say).

I pass the value into my library as a string to circumvent possible byte order problems.

Why does Jade not accept the Binary as a "bucket" for the float type of the library? Or, is there something wrong with the entire approach? Is it somehow possible to "mimick" a 32-bit floating point data type to pass into an external function (as Binary?).

Thanks a lot!

Jens

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: 32-bit-floating point data type

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:34 pm

by Krull >> Wed, 4 Jul 2001 3:22:17 GMT

Hi Jens,
An external function call requires a 32-bit floating point data type
(float) which Jade does not implement.

Actually JADE is supposed to support use of the float type in external functions, try specifying the parameter as Real[4] instead of Real.

In specifying the formal parameters for external functions, Real[4] maps to the C float type, whereas Real or Real[8] maps to a C double. This still compiles, and it did work once but I haven't tried it since JADE 3, so who knows ........

The JADE compiler might also accept Real[10], which previously mapped to a long double but this has since been deprecated due to non-support of the long double type by current Mickeysoft C++ compilers.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: 32-bit-floating point data type

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:34 pm

by JADE Support >> Thu, 5 Jul 2001 3:21:05 GMT

This is covered in detail in the JADE Developers Reference Guide under Chapter 4 Using External Methods and Functions. Specifically in the section for "Parameter Mapping to C Data Types".

Thanks,
Brian Johnstone,
JADE Support.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: 32-bit-floating point data type

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:34 pm

by Jens Richnow >> Fri, 6 Jul 2001 11:22:32 GMT

The Real[4] maps fine to the float data-type in the external functions. It seems to be worthwhile to consult the JADE manuals now and then and not rely entirely on the online help (which does not give any indication of Real[4], Real[8] and Real[10]...)

Thanks!

Jens

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: 32-bit-floating point data type

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:34 pm

by Tim >> Sat, 16 Aug 2008 8:54:43 GMT

Except that this doesn't always work. The jade compiler doesn't allow real[4] in anyway else but external functions. Take this for example:

msdn.microsoft.com/en-us/library/ms533174(VS.85).aspx msdn.microsoft.com/en-us/library/ms533169(VS.85).aspx

Set world transform requires the xform structure passed by reference so that requires using an jade binary. I can create wrapper methods to be used but there is no way to convert the real into 4 bytes in my own methods. I can create my own method to return a binary representation of the 4 byte equivalent of a real but its much more awkward than enabling it as a primitive type.


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 21 guests