-
Notifications
You must be signed in to change notification settings - Fork 1k
Add exact and inexact to cptypes #991
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
base: main
Are you sure you want to change the base?
Conversation
Also, try to change $value to fl+ to allow flonum unboxing later
Rename the library version. it makes more sense add a $ to the name, because it has a who argument. And remove flonum? because it's already checked in cpprim.
mflatt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first two commits look good as far as I can tell. I have some suggestions for the third commit.
| (%typed-object-check mask-inexactnum type-inexactnum ,e-x)) | ||
| ,e-x | ||
| ,(build-libcall #t src sexpr inexact e-x)))))]) | ||
| (define-inline 2 exact->inexact |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like too much code duplication. Add a build-exact->inexact parameterized over the library entry to call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The (small) problem is that build-libcall is a macro that expect an not-quoted version of the name of the library call. So build-exact->inexact must be a macro too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or pass in a function like(lambda (e-x) (build-libcall #t src sexpr inexact e-x)). I'd say the goal isn't to avoid every bit of duplication, but to get most of it.
| ,e-x | ||
| ,(build-libcall #t src sexpr exact->inexact e-x)))))]) | ||
| ) | ||
| (define-inline 2 exact |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I share your reluctance about these. Maybe if they included conversion from integer flonums that are small enough to fit into a fixnum? Otherwise, I'd be inclined to leave them out until motivated by a use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like (copiying from #2%flonum->fixnum)
,(build-and
(build-fl< e-x `(quote ,(constant too-positive-flonum-for-fixnum)))
(build-fl< `(quote ,(constant too-negative-flonum-for-fixnum)) e-x))
I'll try tomorrow, because I prefer to see the code to think about it, but I'm still not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code should check that it's an integer flonum. flonum->fixnum just truncates the value. To check that one possibility is to look if the exponent is big enough, but that will detect only very big flonums, bigger than ~2^54 that are not very interesting (and I'm missing 0.0 and inf.0). It looks too hard to do something interesting with fast code.
I'll try to add the most interesting cases to cptypes instead.
|
By the way, in primdata.ss there is a primitive that is unused. |
And a few related changes ...
Add exact and inexact to cptypes
This is the main part, it has a few subparts inside the same commit:
Add
inexactto cptypes: The old implementation ofreal->flonumcallsinexactand this goes in the "wrong" direction of detail level, and it cause a problem when I addinexactto cptypes (or perhaps when I addinexactto cpprim). So I added a new function$real->flonumto 5_3.ssAdd
exactto cptypes: The problem is thatexactis not total, and the domain is unusual, so it can't be converted to the unsafe version automatically, so I added a special case. An alternative is to add a new typecomplex-rationalto primvars.ms and then change the signature to(exact? [sig [(complex-rational) -> (boolean)]] ...). (Side note: Also, the handle has a special case to collaborate withzero?that is where I notice the problem of moving stuff from the tail position to non-tail.)Replace
$valuewithfl+: This is an experimental idea. I'd like to add in the future a fewfl+here and there so laternp-unbox-fp-vars!can unbox more flonums. I'm not sure when it's a good idea to add newfl+, but replacing some$valuewithfl+looks like a win.Reverse arguments of $real->flonum
Rename in library
real-flonumto$real-flonumbecause it has two arguments like the primitive with the same name.Also, in all (most?) of the other cases,
whois the first argument. I'm not sure if it's necessary to keep backward compatibility at with the system functions.Both changes are just cosmetic, but they make the code more consistent.
Add exact and inexact to cpprim
I'm not very happy with this third part. There is too little work to do and it may increase the executable file size without increasing speed. Perhaps
inexactis interesting butexacthas too few possible improvements unless I add a lot of code to cpprim.(The boot files have probably only a stub for the increase of items in the library, without the implementation.)