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

RealFloat Zero Padded Exponent #643

Open
BebeSparkelSparkel opened this issue Jan 16, 2024 · 7 comments
Open

RealFloat Zero Padded Exponent #643

BebeSparkelSparkel opened this issue Jan 16, 2024 · 7 comments

Comments

@BebeSparkelSparkel
Copy link
Contributor

BebeSparkelSparkel commented Jan 16, 2024

Some dxf files have doubles encoded in scientific notation with the exponent padded with zeros.

https://github.com/LibreCAD/LibreCAD/blob/8e10245994d8307a76cedc3cbffe471de88c8325/librecad/support/library/algoritm/alg27.dxf#L1560

I suggest adding a Bool to FGeneric and FScientific to allow for padding the exponent with zeros to the maximum precision of the exponent.

@clyring
Copy link
Member

clyring commented Jan 24, 2024

Perhaps the way to support this is a higher-order interface that takes displayExponent :: Int -> Builder. Then you could write such a function that prints an exponent of 0 as E+000 or one that dislays it as e0. That seems a bit less nasty than having a bunch of flags for 'is e capitalized' and 'should a + be written for positive exponents' and 'should the exponent be zero-padded'.

Another idea is to provide a function of type Double -> (Builder, Int) where the Builder prints just the mantissa and the Int is the exponent.

@BebeSparkelSparkel
Copy link
Contributor Author

This is much more flexible. Thank you for the idea.

@BebeSparkelSparkel
Copy link
Contributor Author

@clyring I have been unable to make your suggestion performant. I have tried several ways but am consistently getting results that are 150-300% slower. Could you make some recommendations on how modify the overhaul-realfloat branch to implement your suggested change?

@BebeSparkelSparkel
Copy link
Contributor Author

This seems to be going beyond the intended capabilities of the intended formatting capabilities.

@clyring
Copy link
Member

clyring commented Jan 27, 2024

@clyring I have been unable to make your suggestion performant. I have tried several ways but am consistently getting results that are 150-300% slower. Could you make some recommendations on how modify the overhaul-realfloat branch to implement your suggested change?

I'd expect there is a practical way to get an appropriately general interface for this without requiring such a performance hit. Perhaps using BoundedPrim instead of Builder helps? Or maybe we need to get the right amount of inlining to happen? But I don't have the spare focus to dig into this yet.

But it would be nice to provide an interface flexible enough to support this. Let's leave the issue open for now.

@BebeSparkelSparkel
Copy link
Contributor Author

I have been thinking about this and perhaps the most flexible option for printing both the mantissa and exponent would be to extract F2S, D2S, and their dependencies that calculate the digits word and exponent integer to a new package. This would allow the most flexibility for custom printing of the mantissa and exponent and would allow other text types to use it for their own printing implementations.

@BebeSparkelSparkel
Copy link
Contributor Author

Also, a problem with your proposed approach. FStandard does not use this so formatFloating cannot return (Builder, Int).

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

Successfully merging a pull request may close this issue.

2 participants