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

Problems with <double-float> on 64-bit #1254

Closed
pedro-w opened this issue Sep 11, 2019 · 4 comments
Closed

Problems with <double-float> on 64-bit #1254

pedro-w opened this issue Sep 11, 2019 · 4 comments

Comments

@pedro-w
Copy link
Contributor

pedro-w commented Sep 11, 2019

While investigating floating point things on 64-bit, C back end.

There are failing tests in common-dylan/tests/functions.dylan, one example is on line 1002

assert-equal(classify-double-float(#x00000000, #x7ff00000), #"infinite");

Should create a float from the raw data 0x7FF0000000000000
Calling

define inline function classify-double-float (low-bits, high-bits)
=> (classification :: <float-classification>)
classify-float(encode-double-float(as(<machine-word>, low-bits),
as(<machine-word>, high-bits)))
end function classify-double-float;

Calling
define inline-only function encode-double-float
(low :: <machine-word>, high :: <machine-word>) => (encoded :: <double-float>)
primitive-raw-as-double-float
(primitive-cast-machine-words-as-double-float(primitive-unwrap-machine-word(low),
primitive-unwrap-machine-word(high)))
end function encode-double-float;

Calling
DDFLT primitive_cast_machine_words_as_double_float(DUMINT low, DUMINT high) {
INTDFLT intflt;
#ifdef NO_LONGLONG
ignore(high);
intflt.i = (DULMINT)low;
#else
intflt.i = ((DULMINT)high << LONG_BIT) | (DULMINT)low;
#endif
return(intflt.f);
}

For X64, NO_LONGLONG is defined so this is not going to work as it is assuming all 64 bits are in the low machine-word and nothing useful is in the high MW.

Hence in this case, the test fails as the number appears to be zero rather than infinite (I think classify-float itself is OK)

@pedro-w
Copy link
Contributor Author

pedro-w commented Sep 11, 2019

I see it is possible to just directly use a 64 bit number on 64 bit platforms

assert-equal(classify-double-float(#x7ff0000000000000, #x00000000), #"infinite");

so we just need to check $machine-word-size at the appropriate time.
Still would be better if it were possible to specify a sized integer independent of the platform!

@housel
Copy link
Member

housel commented Sep 11, 2019

housel@e20f211 has a fix for this, consistently splitting <double-float> across two machine words on both 32-bit and 64-bit platforms.

@pedro-w
Copy link
Contributor Author

pedro-w commented Sep 11, 2019

That looks like a good change, would it be worth cherry-picking from your branch? (I don't think your corba-tuneup branch has been merged?)

@waywardmonkeys
Copy link
Member

@housel did cherry-pick it and submit it as a PR (#1255), which has now been merged to master.

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

3 participants