2

How are operators overloaded for numbers? I need this for replacing the standard floating point numbers in Lua with big floats (384 bit floats from Cephes) that I've added as a library without having to change Lua itself. The reason is that sometimes normal Lua doubles get mixed up with the big floats if you don't convert the Lua doubles to big floats first.

Can it be done with just some Lua code, or does Lua have to be changed (not necessarily a problem, but still undesirable)?

6
  • 1
    You cannot overload operators for native numbers. But you can and should do it for big floats and such. See my libraries on how to do it: webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua , especially lmapm and lqd.
    – lhf
    Apr 17, 2015 at 18:49
  • That's a pity. I've already added the operators to the big float library I'm using (this causes doubles and big floats to get mixed up sometimes unless you convert the doubles to big float first).
    – Thorham
    Apr 17, 2015 at 19:12
  • If can share your library, I'd like to have a look. Thanks.
    – lhf
    Apr 17, 2015 at 20:00
  • Sure. lcephes.c lcephes.h I've based it on lmapm, and uses Cephes' qfloats. It's still a little rough around the edges here and there, and needs a better allocater for new big floats (simply uses malloc and free for now).
    – Thorham
    Apr 17, 2015 at 20:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.