[haxe] epsilon constant and ≈

196 views
Skip to first unread message

Justin L Mills

unread,
Dec 27, 2015, 7:59:13 AM12/27/15
to haxe...@googlegroups.com
Haxe currently has no epsilon constant, but it is likely that the minimum Float value above or below 0 will vary between targets,
and that may not be an easy value to check since it may vary depend on 64 and 32 bit flags used for instance?
Also Haxe does not have

>

<

operators which could use the epsilon minimum value in comparisom.
Maybe there is a macro that adds this functionality easily to Haxe, I just thought it might be a nice feature that should be realtively easy to implement without side effects, a feature most languages don't have because you may usually know the minimum but for cross target it becomes more important?
I would suggest the epsilon should be user adjustable.

within Math's class as... ( but maybe hard for flash target? )
public static inline var epsilon: Float = 0.0000000001;

Some small maths features such as this are useful in attracting more interest from the scientific and math communities who often need to make thier work more graphical for general public interaction, after all c++ and fortran are probably not much fun for them :)

Maybe a really terrible idea but seemed like it could be nice feature but maybe it's not worth the effort. Just
≈ is very readable and convienient
and if it's not been considered before I should atleast mention it.

David Elahee

unread,
Dec 27, 2015, 8:09:11 AM12/27/15
to haxe...@googlegroups.com
/jokemode Gosh, How do you even type ≈ on a regular keayboard ? :) /endjokemode

I find this very interesting, I would support an user Abstract tolerance for this operators rather than full Float support for starter.

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.



--
David Elahee


Justin L Mills

unread,
Dec 27, 2015, 8:26:02 AM12/27/15
to haxe...@googlegroups.com
With full Float support you then have the flexibility to redefine it in reference to platform.

Math.epsilon = Math.epsilon*5;

I guess that it can't really be inlined?

David Elahee

unread,
Dec 27, 2015, 8:39:40 AM12/27/15
to haxe...@googlegroups.com
Ah wait a min! Math.epsilon is dependent on IEEE conformance and hardware and cthulian horrors... Haxe's Float is _always_ 64bits as of today, BUT it's epsilon varies if you use ARM in fast ieee or Intel or whatever PSP thing...
So usually people I met (incl myself) that are doing epsilon based computation either compute the epsilon or use 1e-6 (32b) / 1e-10 (64b) and stick with it...( I favor the second approach so I get inlining )

So I still think tolerating it for abstract would be highly sufficient since Float has a static semantic across platforms, thus allowing various FloatXX flavors to be overloaded.

chunbiao huang

unread,
Dec 29, 2015, 6:16:00 AM12/29/15
to haxelang
What time is available? Math.epsilon 

Hugh

unread,
Jan 3, 2016, 11:42:16 PM1/3/16
to Haxe
You can use 'using' to add functions to Float, like:

using FloatTools;

if ( 5.10000001.isAlmost(5.1))

Not quite syntax, but not that much worse.
 
Hugh

Mark Knol

unread,
Jan 7, 2016, 12:00:18 PM1/7/16
to Haxe
I use this function to check it:

public static inline function approximately(a:Float, b:Float):Bool {
  return abs(b - a) < max(1E-06 * max(abs(a), abs(b)), -1.79769313486231e+308 * 8.0);
}


Reply all
Reply to author
Forward
0 new messages