Re: [m-users.] How to convert float to uint64?

Xin Wang <[email protected]>
Newsgroups gmane.comp.lang.mercury.general
Message-ID <CAHjSAjWVyYiWE2saHxAhNrN+QouMKp3V7YDWxJz=dOBs2JAc8Q@mail.gmail.com>
On 1/18/23, M McDonough <[email protected]> wrote:
> On Tue, 17 Jan 2023, [email protected] wrote:
>
>> While uint64 can be converted to float using float.cast_from_uint64/1 in
>> Mercury, but I can not find a way to convert float to
>> uint64.
>>
>> Am I missing something?
>
> A quick hack you could use to make this work by "doing whatever C does":
>
> :- func uint64_to_float(uint64) = float.
> % Somewhere later...
> :- pragma foreign_proc("C", uint64_to_float(U::in) = (F::out),
>     [will_not_call_mercury, promise_pure, thread_safe,
>     will_not_throw_exception, may_duplicate, does_not_affect_liveness],
>     " F = U; ").
>
> Similar code could be used for Java and C#. This method is going to
> cause weird or unexpected stuff to happen with very large integer
> values, which will be particularly easy on single-precision-float
> grades.
>

Thanks for your idea! I think I should do it the other way around,
float_to_uint64. :D

Regards,
Xin Wang
_______________________________________________
users mailing list
[email protected]
https://lists.mercurylang.org/listinfo/users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.