The easy way for approximate equality testing is ~ (
http://docs.factorcode.org/content/word-~,math.functions.html )

Also, like björne said, in your case the simplest answer is to use {
-40-1/2 } [ ... ] unit-test  or { -81/2 } [ ... ] unit test.

If you really want to see "-40.5" in the source, you can use the decimals
vocab from extra along with the literals vocab:
${ DECIMAL: -41.5 decimal>ratio }

If you want to see "-40.5" in the unit-test output, then use { t } [
DECIMAL: -41.5 decimal>ratio = ] unit test or { t } [ -41.5 number= ], but
comparing floats has precision problems.


Jon

On Fri, Jan 20, 2017 at 10:37 AM, Jim Mack <j...@less2do.com> wrote:

> Could you subtract the two numbers, then check the abs value < 0.001?
>
> On Thu, Jan 19, 2017 at 11:06 PM, Björn Lindqvist <bjou...@gmail.com>
> wrote:
>
>> If you enter -81/2 instead of -40.5 it should work.
>>
>> 2017-01-20 0:07 GMT+01:00 Alexander Ilin <ajs...@yandex.ru>:
>> > Thank you, Jon, now I understand what the problem is.
>> > Unfortunately, in my case I can't use `number=` because the comparison
>> is
>> > done by the unit-test word.
>> > In the following code the first test succeeds, but the second one fails:
>> >
>> > ```
>> > { 15 } [ 10 20 middle ] unit-test
>> > { -40.5 } [ -50 -31 middle ] unit-test
>> > ```
>> >
>> > 20.01.2017, 01:30, "Jon Harper" <jon.harpe...@gmail.com>:
>> >
>> > Hi,
>> > you have to use number= to compare numbers with different types.
>> > http://docs.factorcode.org/content/word-number=,math.html
>> >
>> > Jon
>> >
>> > Jon
>> >
>> > On Thu, Jan 19, 2017 at 10:50 PM, Alexander Ilin <ajs...@yandex.ru>
>> wrote:
>> >
>> > Hello!
>> >
>> >   I'm a bit confused. Why is following not true?
>> >
>> >   `81/2 40.5 =`
>> >
>> > ---=====---
>> >  Александр
>> >
>> > ------------------------------------------------------------
>> ------------------
>> > Check out the vibrant tech community on one of the world's most
>> > engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>> > _______________________________________________
>> > Factor-talk mailing list
>> > Factor-talk@lists.sourceforge.net
>> > https://lists.sourceforge.net/lists/listinfo/factor-talk
>> >
>> > ,
>> >
>> > ------------------------------------------------------------
>> ------------------
>> > Check out the vibrant tech community on one of the world's most
>> > engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>> >
>> > ,
>> >
>> > _______________________________________________
>> > Factor-talk mailing list
>> > Factor-talk@lists.sourceforge.net
>> > https://lists.sourceforge.net/lists/listinfo/factor-talk
>> >
>> >
>> >
>> > ---=====---
>> > Александр
>> >
>> >
>> > ------------------------------------------------------------
>> ------------------
>> > Check out the vibrant tech community on one of the world's most
>> > engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>> > _______________________________________________
>> > Factor-talk mailing list
>> > Factor-talk@lists.sourceforge.net
>> > https://lists.sourceforge.net/lists/listinfo/factor-talk
>> >
>>
>>
>>
>> --
>> mvh/best regards Björn Lindqvist
>>
>> ------------------------------------------------------------
>> ------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>> _______________________________________________
>> Factor-talk mailing list
>> Factor-talk@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>
>
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to