Jump to content
Sign in to follow this  
Dave

Floating Point Library

Recommended Posts

Hi all.

 

The first release of the floating point library based on the softfloat library by John R. Hauser:

Floating Point Lib V1.0 - this link is only temporary, so may not work in future. To use these libraries (assuming standard installation path of "C:\Program Files\SourceBoost\") you need to:

1) copy the float.picxx.lib files to "C:\Program Files\SourceBoost\lib"

2) copy the float.h file to "C:\Program Files\SourceBoost\include"

3) copy the supplied project to where ever you like.

 

Remember to add the use include <float.h> in the source code and add float.picxx.lib file to the project you want to use it in.

 

Its taken some time to get this done (appologies for that), in fact I've been working on this on and off for over a year :(.

 

It is not as slick as true native floating point support. You have to have to code its like this:

#include <system.h>
#include <float.h>

float CalcCircleArea( float radius )
{
    // area of circle = pi * (radius^2)
    // initiall x holds the radius
    float x;
    x = float32_mul( radius, radius );
    x = float32_mul( x, 3.1415927 );
    return x;
}

void main()
{
    // calc area of a circle
    // area = pi * r * r
    float area = CalcCircleArea( 21.75 );
    int iArea = float32_to_int32( area );

    while( 1 );
}

 

Originally the code would compile under BoostC, but was just to big to fit.

Most effort was spent on making add, sub, mul and div better suited to a small target such as the PIC.

 

The code has been subjected to alot of automated testing, all changes proven to still function as the original using John R. Hauser soft float test suite.

 

So this code is as IEEE754 compliant as the original softfloat code which means its pretty darn good (well done John R. Hauser), supporting exception flagging and all the rounding modes ;).

 

There is still some room for improvement regarding code size and RAM usage (especially with some of the functions I haven't touched, eg float32_eq), but I thought better to get it out there in a usable form and improve things from that point.

 

Any comments greatfully received

 

Regards

Dave

Share this post


Link to post
Share on other sites

Hello Dave

 

I have been trying to get your float library to subtract. Here is the command I am passing.

 

dec_temp = float32_sub(print_temp, FCV_WHOLE);

 

print_temp and dec_temp are type float.

FCV_WHOLE is type int.

 

The other functions work eg multiply and round etc.

 

I have also tried

 

dec_temp = float32_addsub(print_temp, FCV_WHOLE, 1);

 

In both cases the compiler comes back with the following message.

 

error: arguments of 'float32_addsub' don't match the parameters of call

error: failed to generate expression

error: invalid operand 'float32_addsub( print_temp, FCV_WHOLE, 1 )'

error: failed to generate expression

 

Any help you can provide would be appreciated.

Share this post


Link to post
Share on other sites

Benj,

I have been trying to get your float library to subtract. Here is the command I am passing.

 

dec_temp = float32_sub(print_temp, FCV_WHOLE);

 

print_temp and dec_temp are type float.

FCV_WHOLE is type int.

 

The other functions work eg multiply and round etc.

 

I have also tried

 

dec_temp = float32_addsub(print_temp, FCV_WHOLE, 1);

 

In both cases the compiler comes back with the following message.

 

error: arguments of 'float32_addsub' don't match the parameters of call

error: failed to generate expression

error: invalid operand 'float32_addsub( print_temp, FCV_WHOLE, 1 )'

error: failed to generate expression

Try this:

#include <system.h>
#include <float.h>

void main()
{
float res =	float32_sub( 10.0, 9.0 );

while(1);
}

You also will need to add float.pic16.lib or float.pic18.lib to the project.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Benj,

I have been trying to get your float library to subtract. Here is the command I am passing.

 

dec_temp = float32_sub(print_temp, FCV_WHOLE);

 

print_temp and dec_temp are type float.

FCV_WHOLE is type int.

 

The other functions work eg multiply and round etc.

 

I have also tried

 

dec_temp = float32_addsub(print_temp, FCV_WHOLE, 1);

 

In both cases the compiler comes back with the following message.

 

error: arguments of 'float32_addsub' don't match the parameters of call

error: failed to generate expression

error: invalid operand 'float32_addsub( print_temp, FCV_WHOLE, 1 )'

error: failed to generate expression

I responded a little too quickly last time :blink: , so ignore that post !

You need to convert any integer arguments using the float32_from_int32 function before calling the floating point functions.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Hello Dave

 

Thanks for the help I was able to get the Float library working.

 

We have now upgraded our BoostC compiler and have run into difficulties again.

 

Now when trying to compile with the Floating point library I get the following error message.

 

Error: .obj or .lib file Incompatible version! (file uses V107, linker requires V109 to V109)

Error: Failed to process:float.pic16.lib

 

Is there a newer version of this file.

 

Thanks.

Share this post


Link to post
Share on other sites

Benj,

Hello Dave

 

Thanks for the help I was able to get the Float library working.

 

We have now upgraded our BoostC compiler and have run into difficulties again.

 

Now when trying to compile with the Floating point library I get the following error message.

 

Error: .obj or .lib file Incompatible version! (file uses V107, linker requires V109 to V109)

Error: Failed to process:float.pic16.lib

 

Is there a newer version of this file.

 

Thanks.

The latest librarby build of the floating point libs is included in the lastest SourceBoost software package.

Download it from here:http://www.sourceboost.com/CommonDownload.html

 

Regards

Dave

Share this post


Link to post
Share on other sites
Benj,
Hello Dave

 

Thanks for the help I was able to get the Float library working.

 

We have now upgraded our BoostC compiler and have run into difficulties again.

 

Now when trying to compile with the Floating point library I get the following error message.

 

Error: .obj or .lib file Incompatible version! (file uses V107, linker requires V109 to V109)

Error: Failed to process:float.pic16.lib

 

Is there a newer version of this file.

 

Thanks.

The latest librarby build of the floating point libs is included in the lastest SourceBoost software package.

Download it from here:http://www.sourceboost.com/CommonDownload.html

 

Regards

Dave

 

Thanks Dave.

 

Once again you have sorted me out.

 

Many Thanks

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...