Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float literal exceeding type exponent produces error in C backend #1111

Open
demoitem opened this issue Nov 1, 2022 · 9 comments
Open

Float literal exceeding type exponent produces error in C backend #1111

demoitem opened this issue Nov 1, 2022 · 9 comments

Comments

@demoitem
Copy link
Contributor

demoitem commented Nov 1, 2022

Declaring a REAL variable
r := 1.23E123; (the exponent's legal range is -37..38 from memory)

produces error Infinity not declared in this scope in the C backend.
Similarly for LONGREAL and EXTENDED (although they are the same)
for exponents exceeding 308.

@RodneyBates
Copy link
Contributor

RodneyBates commented Nov 1, 2022 via email

@demoitem
Copy link
Contributor Author

demoitem commented Nov 2, 2022 via email

@VictorMiasnikov
Copy link
Contributor

VictorMiasnikov commented Nov 2, 2022

Thoughts?

"EXTENDED changed to 128 bit floats __float128" is good idea.

the Windows backend

Are You about AMD64_NT or AMD64_MINGW?

P.S.

if I could find a windows version of quadmath

It looks like we can try 1 .. 3 variants:

3)

https://www.boost.org/doc/libs/master/libs/math/doc/html/math_toolkit/float128.html
= =
( . . .) or the _Quad type provided by the Intel compiler.
= =

2)

https://www.codeproject.com/Articles/1206126/Quadruple-precision-floating-point-calculations-in
= =
Creation a numeric library that calculates with quadruple floating-point precision and used from MSVC C/C++ code
= =

1)
https://github.com/coder0xff/QPFloat/
= = =

# QPFloat (GPL 3.0) #

For high-precision mathematics, the Quadruple-Precision Floating Point library (QPFloat) emulates the IEEE 754 2008 binary128 on x86, and x64

  . . .

### Microsoft Visual C++ ###
* This code base can be compiled  ( . . .)

= = =

P.P.S.

use the llvm backend on windows

It is good variant too

@VictorMiasnikov
Copy link
Contributor

VictorMiasnikov commented Nov 2, 2022

Declaring a REAL variable r := 1.23E123; (the exponent's legal range is -37..38 from memory)

produces error Infinity not declared in this scope in the C backend. Similarly for LONGREAL and EXTENDED (although they are the same) for exponents exceeding 308.

Can You try this variant?
r := 1.23x923

@demoitem
Copy link
Contributor Author

demoitem commented Nov 2, 2022 via email

@VictorMiasnikov
Copy link
Contributor

They are not assignable if r is REAL. Type mismatch. Does not get to the backend.

Ok . . .

P.S.

LLVM13 has been built on Linux:
= = =
(Debian 11.3.0-1) 11.3.0 versions- cm3: d5.11.9 llvm: 13.0.1
= = =
and can re-build other cm3 packets

@jaykrell
Copy link
Contributor

Can we have the frontend output, like integers to initialize floats?
Like knowing deeply the format?
Or, alternatively, output pieces in a portable idealistic form, like 32 bit sign, 64bit exponent (not biased), 64bit mantissa (possibly with leading 1), and then leave the C backend to know the bitfield sizes, order, and bias?
Probably slightly more elaborate in terms of the leading 1 on mantissa and denormals, and maybe an enum to list special cases like inf, -inf, etc.?

You know, I don't want strings.
I am not sure where I want floating point formats to be known.
I want the C backend to have a chance of outputing ifdef endian and output both orders, so the C source is portable, etc.
I don't want the frontend to know endian, ideally, or even word size, ideally, though these are known currently, and 32bit and big endian are dying, granted.

@RodneyBates
Copy link
Contributor

RodneyBates commented Dec 17, 2022 via email

@jaykrell
Copy link
Contributor

jaykrell commented Jun 3, 2023

as result of grafting a back end with higher-level
output than what the front end is designed to produce.

This is not fair. While the backend format might seem very low level, and C might seem very high level, they do actually fit together pretty well. The C we translate to is not idiomatic C, or readable, or even very portable (it embeds word size and sometimes endian), but it works quite well anyway.

I do agree it'd be nice to optionally raise the representation in some cases.
We should output names with field references though, not just offsets.
Record fields access should be by name. For the front/middle end to do layout should be optional.
sizeof(integer) should not be evaluated by the front/middle end.
So then the C output might be word size neutral.

I've seen projects that raise binaries to C, which is a far larger raise than M3 IR to C.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants