English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 08 July 2021, 14:40   #21
deimos
It's coming back!
 
deimos's Avatar
 
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
Quote:
Originally Posted by alkis View Post
There shouldn't be different if your values are within FFP range. If they are not then you have other problems. If they are, then the conversion should work.
I don't want to.
deimos is offline  
Old 13 July 2021, 11:17   #22
deimos
It's coming back!
 
deimos's Avatar
 
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
So, something like this:

Code:
    // to do, this afternoon
    constexpr FFP composeffp(const LONG mantissa, const LONG exponent) {
        return exponent;
    }

    constexpr FFP r(const char * s) {
        FFP n = 0;

        LONG mantissa = 0L;
        LONG exponent = 0L;

        bool negativeMantissa = false;
        bool negativeExponent = false;

        bool parsingExponent = false;

        for (const char * p = s; *p; *p++) {
            const char c = *p;

            if (!parsingExponent) {
                if (c >= '0' && c <= '9')
                    mantissa = mantissa * 10 + (c - '0');
                else if (c == '-')
                    negativeMantissa = true;
                else if (c == 'e' || c == 'E')
                    parsingExponent = TRUE;
            } else {
                if (c >= '0' && c <= '9')
                    exponent = exponent * 10 + (c - '0');
                else if (c == '-')
                    negativeExponent = TRUE;
            }
        }

        if (negativeMantissa)
            mantissa = -mantissa;
        
        if (negativeExponent)
            exponent = -exponent;

        return composeffp(mantissa, exponent);
    }
deimos is offline  
Old 13 July 2021, 14:15   #23
deimos
It's coming back!
 
deimos's Avatar
 
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
I have also just found this:

https://github.com/xroche/ieee754toy

Which looks like it does a more advanced version of what I'm trying to do. I'm still trying to understand it properly, it uses more things that are new to me, like function templates.
deimos is offline  
Old 13 July 2021, 18:55   #24
Jobbo
Registered User
 
Jobbo's Avatar
 
Join Date: Jun 2020
Location: Druidia
Posts: 387
For what it's worth I updated my code so it can generate instances of my ffp class from native floats at compile time and vice versa.

I didn't port the 68000 assembler versions, which seems to be what alkis has done. Those versions are pretty hard to follow. Instead I wrote simple to follow C versions.

That doesn't help you with your string parser but my versions are maybe useful to others.

https://github.com/rjobling/ffloat
Jobbo is online now  
Old 13 July 2021, 19:12   #25
deimos
It's coming back!
 
deimos's Avatar
 
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
Quote:
Originally Posted by Jobbo View Post
For what it's worth I updated my code so it can generate instances of my ffp class from native floats at compile time and vice versa.

I didn't port the 68000 assembler versions, which seems to be what alkis has done. Those versions are pretty hard to follow. Instead I wrote simple to follow C versions.

That doesn't help you with your string parser but my versions are maybe useful to others.

https://github.com/rjobling/ffloat
And, of course, that's a perfectly valid and useful thing to do, it's just not the thing I want to do. I want to create a perfect 1:1 compatibility with the Motorola format. I don't think the C++ code for that will be big, but, yes, it's not easy to follow the assembly code. I'm making very slow progress.
deimos is offline  
Old 13 July 2021, 19:30   #26
Jobbo
Registered User
 
Jobbo's Avatar
 
Join Date: Jun 2020
Location: Druidia
Posts: 387
As far as I'm aware all the versions we've posted do the best job possible to translate from IEEE to FFP, and a perfect job translating from FFP to IEEE.
Jobbo is online now  
Old 13 July 2021, 19:53   #27
deimos
It's coming back!
 
deimos's Avatar
 
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
Quote:
Originally Posted by Jobbo View Post
As far as I'm aware all the versions we've posted do the best job possible to translate from IEEE to FFP, and a perfect job translating from FFP to IEEE.
I have no interest in translating from IEEE to FFP. I just want to construct FFP numbers.

In any case, there can be no such thing as a perfect job of translating between the formats, as they have different ranges and precisions. Not every number that can be exactly represented by IEEE be exactly represented in FFP, and visa versa.

Now, of course, loads of adenoids will come along to explain that floating point numbers should always be treated as approximations and never compared directly, etc. etc., but I don't care about that, I don't want one part of my code base converting a string to one number and another part converting the exact same string to a slightly different number.
deimos is offline  
Old 13 July 2021, 20:39   #28
Jobbo
Registered User
 
Jobbo's Avatar
 
Join Date: Jun 2020
Location: Druidia
Posts: 387
Quote:
Originally Posted by deimos View Post
In any case, there can be no such thing as a perfect job of translating between the formats, as they have different ranges and precisions. Not every number that can be exactly represented by IEEE be exactly represented in FFP, and visa versa.

That's incorrect. All valid FFP numbers have an IEEE equivalent.


Here is the original code I had copied which has some comments.



https://github.com/ggnkua/Atari_ST_S...FFP/FFPIEEE.SA



You can also read the FFP format description in the Amiga libs documentation.


http://amigadev.elowar.com/read/ADCD.../node047D.html
Jobbo is online now  
Old 13 July 2021, 21:19   #29
deimos
It's coming back!
 
deimos's Avatar
 
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
You've just made up my mind. I have better, more interesting things to do than develop for the Amiga.
deimos is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating an accurate Paula period table 8bitbubsy Coders. General 55 07 September 2020 21:04
Wanted: C source for converting gcc (linux) float to FFP alkis Coders. C/C++ 5 16 August 2020 02:39
Integers vs floats (FFP/Sing/Doub) + printf() guy lateur Coders. Asm / Hardware 63 18 July 2017 17:57
WinUAELoader: generating single game .uae? Telegattone support.WinUAE 1 27 December 2016 12:28
Software for generating screenshots and videos Edi (FZ2D) Retrogaming General Discussion 5 08 April 2010 23:34

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:31.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.08884 seconds with 13 queries