new floating point support, maybe bug ??

Freeform discussion about anything related to modding Transcendence.
Post Reply
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

Hi, I was making some tests with the new floating point support functions:

so the new functions for those who missed George post are: + - * / mod pow sqrtn

the old corresponding functions that works with integers only are: add subtract multiply divide modulo power sqrt

you can check with the function (typeof number) if a number is an integer or real

so

(- 2.1 2) returns 0.1

(subtract 2.1 2) returns 0 (no support for real numbers)

in particular - or + will convert an integer number to a real one

(+ 1 1) returns 2.0 (the decimal 0 is a nice touch to actually see immediately the real number)

-------
NOW the problem:

I think that add function is broken for real numbers
before making the ministry ticket, I would like confirmation:

(add 1 1.0) I would it expect to return 2, instead it returns 2.0, a real number ??

(add 2.1 2) returns 4.099999904632568

subtract seems fine, and it will truncate the number to an integer, dropping the decimals properly.

Didn't try the others.
giantcabbage
Militia Lieutenant
Militia Lieutenant
Posts: 104
Joined: Thu Apr 07, 2011 9:05 pm

add and + do the same thing (at least in 1.6.2 RCs). However, other functions are inconsistent:

add multiply + - * mod use standard promotion rules (i.e. 1+1 = 2 but 1+1.0 = 2.0)
/ pow sqrtn always promote to real
subtract divide modulo power sqrt always use integer arithmetic

I would suggest standard promotion rules for all functions (expect sqrtn which should always promote to real). If you need to force integer arithmetic then you can use the int function.
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

so, add multiply are the only ones that are weird, as they shouldn't promote the numbers at all and use only integers.
Post Reply