Open BebeSparkelSparkel opened 9 months ago
Float
and Double
-formatting code. But using classes to de-duplicate this logic may require considerable care to make sure that all of the actual class-dictionaries are specialized away and all of the unboxing we expect actually happens. (Backpack isn't really an option for us; abusing CPP is another possibility.) I don't expect the cost/benefit to be favorable unless you are rewriting large chunks, but if you want to work on this I won't stop you.1e40
and 1E40
. But Char
is not appropriate here: Word8
for a single byte, or perhaps Builder
is less ugly, or perhaps a Bool
indicating "isUppercase."0.0e0
versus 0.0
.formatDouble
.)(Sorry for taking so long to respond.)
Builder is an intriguing idea instead of char. I'll have to think about that since it does allow for more than one Word8 to be inserted.
I think 6 and 7 are somewhat related and it seems worth it to consolidate for the faster determination of special values for the standard case.
@Bodigrim @clyring I am having a performance problem with trying to consolidate the special printers. When I apply the changes in commit the performance for printing NaN, Infinity, and 0 decreases by 20-70%. Do you have any insight as to why this is?
Baseline profile created from branch realfloat-bench with cabal bench --benchmark-options '--csv baseline.csv -p /RealFloat/'
Compared to baseline on branch consolidate-special-real-number-printers with cabal bench --benchmark-options '--baseline baseline.csv -p "/FSci/ && /Special/ && $NF ~ /Float/"'
I see you're doing a lot of work in various PRs in this area. Please let me know when each one is ready for review, and which ones to start with/prioritize.
@clyring Please focus on
The others can come later.
I have created the following PRs but they seem to be intermingled and perhaps a larger pull would be better
632
633
634
I propose the following
formatFloat
andformatDouble
intoformatFloating :: FloatFormat -> a -> Builder
since they have the same logic and use classes to get their specific functions based on the floating type. Continuing exporting theformatFloat
andformatDouble
interface functions for compatibility.FloatFormat
to the constructors ofFormatMode
and remove the typeFormatMode
because the precision(Maybe Int)
is not used and can be included as a parameter of the constructorsFScientific
should have aChar
for specifying a lower or upper EFStandard
should have aMaybe Int
for the precisionFGeneric
should have a Char for specifying a lower or upper E, and two Ints for the inclusive exponent range for printing the standard notationdata SpecialStrings = {..}
specialStr
and usetoCharsNonNumbersAndZero
instead because they duplicate logic and it is faster to evaluate\f -> ...
should be defined after the case statement and not before.None of these changes should cause changes to the existing interface.