├── .gitignore ├── .haxerc ├── LICENSE ├── README.md ├── build.hxml ├── haxelib.json └── src ├── Entry.hx └── be └── Constant.hx /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ -------------------------------------------------------------------------------- /.haxerc: -------------------------------------------------------------------------------- 1 | { 2 | "version": "4.0.0-preview.5", 3 | "resolveLibs": "scoped" 4 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Skial Bainn 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # min-max 2 | 3 | A small library to provide `min` and `max` cross-platform constants for `Int` and `Float` types. 4 | 5 | ## Install 6 | 7 | - `lix install gh:skial/min-max` 8 | 9 | ## Example 10 | 11 | ```Haxe 12 | package ; 13 | 14 | using be.Constant; 15 | 16 | class Main { 17 | 18 | public static function main() { 19 | trace( Floats.MIN, Floats.MAX, Floats.MIN - 1, Floats.MAX + 1 ); 20 | trace( Ints.MIN, Ints.MAX, Ints.MIN - 1, Ints.MAX + 1 ); 21 | } 22 | 23 | } 24 | ``` -------------------------------------------------------------------------------- /build.hxml: -------------------------------------------------------------------------------- 1 | -cp src 2 | 3 | -main Entry 4 | 5 | #-debug 6 | -dce full 7 | -D analyzer-optimize 8 | 9 | --each 10 | 11 | -js bin/mm.js 12 | 13 | --next 14 | 15 | -python bin/mm.py 16 | 17 | --next 18 | 19 | -php bin/mm 20 | 21 | --next 22 | 23 | -hl bin/mm.hl 24 | 25 | --next 26 | 27 | -neko bin/mm.n -------------------------------------------------------------------------------- /haxelib.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "min-max", 3 | "url": "https://github.com/skial/min-max", 4 | "classPath": "src", 5 | "releasenote": "", 6 | "description": "Provides min and max cross-platform constants for Int and Float types", 7 | "contributors": ["skial"], 8 | "version": "1.0.0", 9 | "tags": ["haxe", "min", "max", "int", "float", "cross-platform"], 10 | "license": "MIT" 11 | } 12 | -------------------------------------------------------------------------------- /src/Entry.hx: -------------------------------------------------------------------------------- 1 | package ; 2 | 3 | using be.Constant; 4 | 5 | class Entry { 6 | 7 | public static function main() { 8 | trace( Floats.MIN, Floats.MAX, Floats.MIN - 1, Floats.MAX + 1 ); 9 | trace( Ints.MIN, Ints.MAX, Ints.MIN - 1, Ints.MAX + 1 ); 10 | } 11 | 12 | } -------------------------------------------------------------------------------- /src/be/Constant.hx: -------------------------------------------------------------------------------- 1 | package be; 2 | 3 | class Constant {} 4 | 5 | typedef Floats = F; 6 | typedef Ints = I; 7 | 8 | // @see https://github.com/HaxeFoundation/as3hx/blob/master/src/as3hx/Compat.hx#L260-L305 9 | @:notNull abstract F(Float) from Float to Float { 10 | public static var MIN(get, never):Float; 11 | 12 | private static inline function get_MIN():Float { 13 | #if flash 14 | return untyped __global__['Number'].MIN_VALUE; 15 | #elseif js 16 | return js.Syntax.code('Number.MIN_VALUE'); 17 | #elseif cs 18 | return untyped __cs__('double.MinValue'); 19 | #elseif java 20 | return untyped __java__('Double.MIN_VALUE'); 21 | #elseif cpp 22 | return 2.2250738585072014E-308; 23 | #elseif hl 24 | // Should be the MIN IEEE double precison float. 25 | // @see https://haxe.org/blog/hashlink-in-depth-p2/ 26 | return 1.1754943508e-38; 27 | #elseif python 28 | return Sys.float_info.min; 29 | #else 30 | return -1.79E+308; 31 | #end 32 | } 33 | 34 | public static var MAX(get, never):Float; 35 | 36 | private static inline function get_MAX():Float { 37 | #if flash 38 | return untyped __global__['Number'].MAX_VALUE; 39 | #elseif js 40 | return js.Syntax.code('Number.MAX_VALUE'); 41 | #elseif cs 42 | return untyped __cs__('double.MaxValue'); 43 | #elseif java 44 | return untyped __java__('Double.MAX_VALUE'); 45 | #elseif cpp 46 | return 1.7976931348623157E+308; 47 | #elseif hl 48 | return 3.4028234664e+38; 49 | #elseif python 50 | return Sys.float_info.max; 51 | #else 52 | return 1.79e+308; 53 | #end 54 | } 55 | } 56 | 57 | @:notNull abstract I(Int) from Int to Int { 58 | public static var MIN(get, never):Int; 59 | 60 | private static inline function get_MIN():Int { 61 | #if flash 62 | return untyped __global__['int'].MIN_VALUE; 63 | #elseif js 64 | return js.Syntax.code('Number.MIN_SAFE_INTEGER'); 65 | #elseif cs 66 | return untyped __cs__('int.MinValue'); 67 | #elseif java 68 | return untyped __java__('Integer.MIN_VALUE'); 69 | #elseif (cpp || hl || neko) 70 | return -2147483648; 71 | #elseif python 72 | return -Sys.maxsize - 1; 73 | #elseif php 74 | return php.Const.PHP_INT_MIN; 75 | #else 76 | return -2147483648;//-2^31; 77 | #end 78 | } 79 | 80 | public static var MAX(get, never):Int; 81 | 82 | private static inline function get_MAX():Int { 83 | #if flash 84 | return untyped __global__['int'].MAX_VALUE; 85 | #elseif js 86 | return js.Syntax.code('Number.MAX_SAFE_INTEGER'); 87 | #elseif cs 88 | return untyped __cs__('int.MaxValue'); 89 | #elseif java 90 | return untyped __java__('Integer.MAX_VALUE'); 91 | #elseif (cpp || hl || neko) 92 | return 2147483647; 93 | #elseif python 94 | return Sys.maxsize; 95 | #elseif php 96 | return php.Const.PHP_INT_MAX; 97 | #else 98 | return 2147483647;//2^31-1; 99 | #end 100 | } 101 | 102 | } 103 | 104 | #if python 105 | @:pythonImport("sys") 106 | private extern class Sys { 107 | public static var maxsize:Int; 108 | public static var float_info:{max:Float, min:Float}; 109 | } 110 | #end 111 | --------------------------------------------------------------------------------