<![CDATA[Scolring - Forum / Compare numbers negatives in scol?]]> 2019-01-06T13:06:17Z FluxBB https://forum.openspace3d.com/viewtopic.php?id=3848 <![CDATA[Re: Compare numbers negatives in scol?]]> Hi !

You should never compare floats in this way, in Scol nor any other language.

To compare two integers, it's ok :

``````if integer1 == integer2 then
...``````

To compare two floats, you compare the difference with an epsilon whose accuracy you arbitrarily choose.

``````if (float1 -. float2) <. epsilon then
_fooS "they are equals"
else
_fooS "They are not equals";``````

You should use the float Scol library : http://redmine.scolring.org/projects/li … float.html (doc)

Your code could be this in h/a.pkg :

``````fun main()=
_showconsole;
let  atof "\$9" -> x in
let " " -> temp_x in
if std_fCmp x (-.255.0) then
set temp_x = ftoa (-.1.0)
else
set temp_x = ftoa 0.0;;``````

Called by a such script :

``````_load "lib/std/float.pkg"
main``````

I use std_fCmp function. By default, epsilon is 0.000001.

You write :

``if x =. -255.0 then``

Also, = sets a value to a variable, so if x = 255.0 then sets 255.0 to x and the expression tests the return value of set, a side effect. This is an equivalent of if set x = 255.0 then ...
if x =. 255.0 then, with a point, create a syntax error : this is no sense in Scol. It's contrary to its grammar.
In a test, you must double the equal sign but with the float numbers, this is wrong (see above).

Next, -255.0 is wrong. Indeed, - (without point) expects an integer.
-. (with point) expects an float, thus (-.255.0) is correct.

If you want compare an integer and a flot, you must convert the integer to float (or the other way around but your can lost the precision)

Then, your variable named x is stange :

``let  atof "\$9" -> x in ``

will always give 0.000000. I guess you wish to get the value of \$9, maybe a parameter into a string ?

]]>
https://forum.openspace3d.com/profile.php?id=3 2019-01-06T13:06:17Z https://forum.openspace3d.com/viewtopic.php?pid=15141#p15141
<![CDATA[Compare numbers negatives in scol?]]> Hi, I need help, how can compare numbers negatives in lenguaje scol?

For example:

let  atof "\$9" -> x in
let " " -> temp_x in

if x =. -255.0 then
(
set temp_x = ftoa(-1.0)
)
else(
set temp_x = ftoa(0.0)
)

This, show error in console.

Thanks so much

]]>
https://forum.openspace3d.com/profile.php?id=2928 2019-01-06T01:27:04Z https://forum.openspace3d.com/viewtopic.php?pid=15140#p15140