Skip to content

Incorrect representation with Schubfach? #13

Description

@blueglyph

With a double-precision value corresponding to the minimum value (hex representation 0x0000000000000001),

  • I'm expecting this string: "4.9E-324"
  • I get this string: "5e-324"

The expected string is coming from the Java implementation from the algorithm's author, Raffaello Giulietti.

I haven't done a more thorough test to see if there were other discrepancies. Most of the results are definitely fine but finding different values, and seeing the algorithm has been adapted, is not reassuring. Perhaps were there small adaptations in the original algorithm? There are several versions of the article.

Quick and dirty test file (requires schubfach_64.cpp and schubfach_64.h)

#include <cstdint>
#include <cstdio>
#include <cstring>
#include "schubfach_64.h"

using namespace std;
using namespace schubfach;

char BUFFER[DtoaMinBufferLength];

char *dtoa(double value)
{
    char *end = Dtoa(BUFFER, value);
    *end = 0;
    return BUFFER;
}

template <typename Dest, typename Source>
static inline Dest ReinterpretBits(Source source)
{
    static_assert(sizeof(Dest) == sizeof(Source), "size mismatch");

    Dest dest;
    std::memcpy(&dest, &source, sizeof(Source));
    return dest;
}

int main()
{
    uint64_t min_value_bits = 0x0000000000000001;
    double min_value = ReinterpretBits<double>(min_value_bits);
    double values[] = { 1.0, 10.0, 0.5, min_value };
    for (double i: values) {
        printf("%g: %s\n", i, dtoa(i));
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions