Mercurial Hosting > luan
comparison website/src/manual.html.luan @ 566:90b93790c544
Number and Math documentation and minor changes
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Sun, 05 Jul 2015 18:26:04 -0600 |
| parents | 22bfd8a2eaee |
| children | 6c00b8a59240 |
comparison
equal
deleted
inserted
replaced
| 565:22bfd8a2eaee | 566:90b93790c544 |
|---|---|
| 90 <li><a href="#default_lib">Default Environment</a></li> | 90 <li><a href="#default_lib">Default Environment</a></li> |
| 91 <li><a href="#luan_lib">Basic Functions</a></li> | 91 <li><a href="#luan_lib">Basic Functions</a></li> |
| 92 <li><a href="#package_lib">Modules</a></li> | 92 <li><a href="#package_lib">Modules</a></li> |
| 93 <li><a href="#string_lib">String Manipulation</a></li> | 93 <li><a href="#string_lib">String Manipulation</a></li> |
| 94 <li><a href="#table_lib">Table Manipulation</a></li> | 94 <li><a href="#table_lib">Table Manipulation</a></li> |
| 95 <li><a href="#number_lib">Number Manipulation</a></li> | |
| 96 <li><a href="#math_lib">Mathematical Functions</a></li> | |
| 95 </ul> | 97 </ul> |
| 96 </div> | 98 </div> |
| 97 | 99 |
| 98 <hr/> | 100 <hr/> |
| 99 | 101 |
| 2763 By default, <code>i</code> is 1 and <code>j</code> is <code>#list</code>. | 2765 By default, <code>i</code> is 1 and <code>j</code> is <code>#list</code>. |
| 2764 | 2766 |
| 2765 | 2767 |
| 2766 | 2768 |
| 2767 | 2769 |
| 2768 | 2770 <h3 heading><a name="number_lib">Number Manipulation</a></h3> |
| 2769 | 2771 |
| 2770 | 2772 <p> |
| 2771 <h2>6.7 – <a name="6.7">Mathematical Functions</a></h2> | 2773 Include this library by: |
| 2774 | |
| 2775 <pre> | |
| 2776 local Number = require "luan:Number" | |
| 2777 </pre> | |
| 2778 | |
| 2779 | |
| 2780 <h4 heading><a name="Number.double"><code>Number.double (x)</code></a></h4> | |
| 2781 <p> | |
| 2782 Returns <code>x</code> as a double. | |
| 2783 | |
| 2784 | |
| 2785 <h4 heading><a name="Number.integer"><code>Number.integer (x)</code></a></h4> | |
| 2786 <p> | |
| 2787 If the value <code>x</code> is convertible to an integer, | |
| 2788 returns that integer. | |
| 2789 Otherwise throws an error. | |
| 2790 | |
| 2791 | |
| 2792 <h4 heading><a name="Number.long"><code>Number.long (x)</code></a></h4> | |
| 2793 <p> | |
| 2794 If the value <code>x</code> is convertible to an long, | |
| 2795 returns that long. | |
| 2796 Otherwise throws an error. | |
| 2797 | |
| 2798 | |
| 2799 <h4 heading><a name="Number.long_to_string"><code>Number.long_to_string (i, radix)</code></a></h4> | |
| 2800 <p> | |
| 2801 Converts long value <code>i</code> to a string by calling <code><a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Long.html#toString(long,%20int)">Long.toString</a></code>. | |
| 2802 | |
| 2803 | |
| 2804 <h4 heading><a name="Number.type"><code>Number.type (x)</code></a></h4> | |
| 2805 <p> | |
| 2806 Returns a string for the numeric type of <code>x</code>. Possible return values include "<code>integer</code>", "<code>long</code>", "<code>double</code>", and "<code>float</code>". | |
| 2807 | |
| 2808 | |
| 2809 | |
| 2810 | |
| 2811 <h3 heading><a name="math_lib">Mathematical Functions</a></h3> | |
| 2812 | |
| 2813 <p> | |
| 2814 Include this library by: | |
| 2815 | |
| 2816 <pre> | |
| 2817 local Math = require "luan:Math" | |
| 2818 </pre> | |
| 2772 | 2819 |
| 2773 <p> | 2820 <p> |
| 2774 This library provides basic mathematical functions. | 2821 This library provides basic mathematical functions. |
| 2775 It provides all its functions and constants inside the table <a name="pdf-math"><code>math</code></a>. | 2822 It provides all its functions and constants inside the table <code>Math</code>. |
| 2776 Functions with the annotation "<code>integer/float</code>" give | 2823 |
| 2777 integer results for integer arguments | 2824 |
| 2778 and float results for float (or mixed) arguments. | 2825 <h4 heading><a name="Math.abs"><code>Math.abs (x)</code></a></h4> |
| 2779 Rounding functions | 2826 |
| 2780 (<a href="#pdf-math.ceil"><code>math.ceil</code></a>, <a href="#pdf-math.floor"><code>math.floor</code></a>, and <a href="#pdf-math.modf"><code>math.modf</code></a>) | 2827 <p> |
| 2781 return an integer when the result fits in the range of an integer, | 2828 Returns the absolute value of <code>x</code>. |
| 2782 or a float otherwise. | 2829 |
| 2783 | 2830 |
| 2784 | 2831 |
| 2785 <p> | 2832 <h4 heading><a name="Math.acos"><code>Math.acos (x)</code></a></h4> |
| 2786 <hr><h3><a name="pdf-math.abs"><code>math.abs (x)</code></a></h3> | |
| 2787 | |
| 2788 | |
| 2789 <p> | |
| 2790 Returns the absolute value of <code>x</code>. (integer/float) | |
| 2791 | |
| 2792 | |
| 2793 | |
| 2794 | |
| 2795 <p> | |
| 2796 <hr><h3><a name="pdf-math.acos"><code>math.acos (x)</code></a></h3> | |
| 2797 | |
| 2798 | 2833 |
| 2799 <p> | 2834 <p> |
| 2800 Returns the arc cosine of <code>x</code> (in radians). | 2835 Returns the arc cosine of <code>x</code> (in radians). |
| 2801 | 2836 |
| 2802 | 2837 |
| 2803 | 2838 |
| 2804 | 2839 |
| 2805 <p> | 2840 <h4 heading><a name="Math.asin"><code>Math.asin (x)</code></a></h4> |
| 2806 <hr><h3><a name="pdf-math.asin"><code>math.asin (x)</code></a></h3> | |
| 2807 | |
| 2808 | 2841 |
| 2809 <p> | 2842 <p> |
| 2810 Returns the arc sine of <code>x</code> (in radians). | 2843 Returns the arc sine of <code>x</code> (in radians). |
| 2811 | 2844 |
| 2812 | 2845 |
| 2813 | 2846 |
| 2814 | 2847 |
| 2815 <p> | 2848 <h4 heading><a name="Math.atan"><code>Math.atan (y, x)</code></a></h4> |
| 2816 <hr><h3><a name="pdf-math.atan"><code>math.atan (y [, x])</code></a></h3> | 2849 |
| 2817 | 2850 <p> |
| 2818 | |
| 2819 <p> | |
| 2820 | |
| 2821 Returns the arc tangent of <code>y/x</code> (in radians), | 2851 Returns the arc tangent of <code>y/x</code> (in radians), |
| 2822 but uses the signs of both parameters to find the | 2852 but uses the signs of both parameters to find the |
| 2823 quadrant of the result. | 2853 quadrant of the result. |
| 2824 (It also handles correctly the case of <code>x</code> being zero.) | 2854 (It also handles correctly the case of <code>x</code> being zero.) |
| 2825 | 2855 |
| 2826 | 2856 |
| 2827 <p> | 2857 |
| 2828 The default value for <code>x</code> is 1, | 2858 |
| 2829 so that the call <code>math.atan(y)</code> | 2859 <h4 heading><a name="Math.ceil"><code>Math.ceil (x)</code></a></h4> |
| 2830 returns the arc tangent of <code>y</code>. | |
| 2831 | |
| 2832 | |
| 2833 | |
| 2834 | |
| 2835 <p> | |
| 2836 <hr><h3><a name="pdf-math.ceil"><code>math.ceil (x)</code></a></h3> | |
| 2837 | |
| 2838 | 2860 |
| 2839 <p> | 2861 <p> |
| 2840 Returns the smallest integral value larger than or equal to <code>x</code>. | 2862 Returns the smallest integral value larger than or equal to <code>x</code>. |
| 2841 | 2863 |
| 2842 | 2864 |
| 2843 | 2865 |
| 2844 | 2866 |
| 2845 <p> | 2867 <h4 heading><a name="Math.cos"><code>Math.cos (x)</code></a></h4> |
| 2846 <hr><h3><a name="pdf-math.cos"><code>math.cos (x)</code></a></h3> | |
| 2847 | |
| 2848 | 2868 |
| 2849 <p> | 2869 <p> |
| 2850 Returns the cosine of <code>x</code> (assumed to be in radians). | 2870 Returns the cosine of <code>x</code> (assumed to be in radians). |
| 2851 | 2871 |
| 2852 | 2872 |
| 2853 | 2873 |
| 2854 | 2874 |
| 2855 <p> | 2875 <h4 heading><a name="Math.deg"><code>Math.deg (x)</code></a></h4> |
| 2856 <hr><h3><a name="pdf-math.deg"><code>math.deg (x)</code></a></h3> | |
| 2857 | |
| 2858 | 2876 |
| 2859 <p> | 2877 <p> |
| 2860 Converts the angle <code>x</code> from radians to degrees. | 2878 Converts the angle <code>x</code> from radians to degrees. |
| 2861 | 2879 |
| 2862 | 2880 |
| 2863 | 2881 |
| 2864 | 2882 |
| 2865 <p> | 2883 <h4 heading><a name="Math.exp"><code>Math.exp (x)</code></a></h4> |
| 2866 <hr><h3><a name="pdf-math.exp"><code>math.exp (x)</code></a></h3> | |
| 2867 | |
| 2868 | 2884 |
| 2869 <p> | 2885 <p> |
| 2870 Returns the value <em>e<sup>x</sup></em> | 2886 Returns the value <em>e<sup>x</sup></em> |
| 2871 (where <code>e</code> is the base of natural logarithms). | 2887 (where <code>e</code> is the base of natural logarithms). |
| 2872 | 2888 |
| 2873 | 2889 |
| 2874 | 2890 |
| 2875 | 2891 |
| 2876 <p> | 2892 <h4 heading><a name="Math.floor"><code>Math.floor (x)</code></a></h4> |
| 2877 <hr><h3><a name="pdf-math.floor"><code>math.floor (x)</code></a></h3> | |
| 2878 | |
| 2879 | 2893 |
| 2880 <p> | 2894 <p> |
| 2881 Returns the largest integral value smaller than or equal to <code>x</code>. | 2895 Returns the largest integral value smaller than or equal to <code>x</code>. |
| 2882 | 2896 |
| 2883 | 2897 |
| 2884 | 2898 |
| 2885 | 2899 |
| 2886 <p> | 2900 <h4 heading><a name="Math.fmod"><code>Math.fmod (x, y)</code></a></h4> |
| 2887 <hr><h3><a name="pdf-math.fmod"><code>math.fmod (x, y)</code></a></h3> | |
| 2888 | |
| 2889 | 2901 |
| 2890 <p> | 2902 <p> |
| 2891 Returns the remainder of the division of <code>x</code> by <code>y</code> | 2903 Returns the remainder of the division of <code>x</code> by <code>y</code> |
| 2892 that rounds the quotient towards zero. (integer/float) | 2904 that rounds the quotient towards zero. |
| 2893 | 2905 |
| 2894 | 2906 |
| 2895 | 2907 |
| 2896 | 2908 |
| 2897 <p> | 2909 <h4 heading><a name="Math.huge"><code>Math.huge</code></a></h4> |
| 2898 <hr><h3><a name="pdf-math.huge"><code>math.huge</code></a></h3> | 2910 |
| 2899 | 2911 <p> |
| 2900 | 2912 A value larger than any other numerical value. |
| 2901 <p> | 2913 |
| 2902 The float value <code>HUGE_VAL</code>, | 2914 |
| 2903 a value larger than any other numerical value. | 2915 |
| 2904 | 2916 |
| 2905 | 2917 <h4 heading><a name="Math.log"><code>Math.log (x [, base])</code></a></h4> |
| 2906 | |
| 2907 | |
| 2908 <p> | |
| 2909 <hr><h3><a name="pdf-math.log"><code>math.log (x [, base])</code></a></h3> | |
| 2910 | |
| 2911 | 2918 |
| 2912 <p> | 2919 <p> |
| 2913 Returns the logarithm of <code>x</code> in the given base. | 2920 Returns the logarithm of <code>x</code> in the given base. |
| 2914 The default for <code>base</code> is <em>e</em> | 2921 The default for <code>base</code> is <em>e</em> |
| 2915 (so that the function returns the natural logarithm of <code>x</code>). | 2922 (so that the function returns the natural logarithm of <code>x</code>). |
| 2916 | 2923 |
| 2917 | 2924 |
| 2918 | 2925 |
| 2919 | 2926 |
| 2920 <p> | 2927 <h4 heading><a name="Math.max"><code>Math.max (x, ···)</code></a></h4> |
| 2921 <hr><h3><a name="pdf-math.max"><code>math.max (x, ···)</code></a></h3> | |
| 2922 | |
| 2923 | 2928 |
| 2924 <p> | 2929 <p> |
| 2925 Returns the argument with the maximum value, | 2930 Returns the argument with the maximum value, |
| 2926 according to the Lua operator <code><</code>. (integer/float) | 2931 according to the Lua operator <code><</code>. |
| 2927 | 2932 |
| 2928 | 2933 |
| 2929 | 2934 |
| 2930 | 2935 |
| 2931 <p> | 2936 <h4 heading><a name="Math.max_integer"><code>Math.max_integer</code></a></h4> |
| 2932 <hr><h3><a name="pdf-math.maxinteger"><code>math.maxinteger</code></a></h3> | 2937 <p> |
| 2933 An integer with the maximum value for an integer. | 2938 An integer with the maximum value for an integer. |
| 2934 | 2939 |
| 2935 | 2940 |
| 2936 | 2941 |
| 2937 | 2942 |
| 2938 <p> | 2943 <h4 heading><a name="Math.min"><code>Math.min (x, ···)</code></a></h4> |
| 2939 <hr><h3><a name="pdf-math.min"><code>math.min (x, ···)</code></a></h3> | |
| 2940 | |
| 2941 | 2944 |
| 2942 <p> | 2945 <p> |
| 2943 Returns the argument with the minimum value, | 2946 Returns the argument with the minimum value, |
| 2944 according to the Lua operator <code><</code>. (integer/float) | 2947 according to the Lua operator <code><</code>. |
| 2945 | 2948 |
| 2946 | 2949 |
| 2947 | 2950 |
| 2948 | 2951 |
| 2949 <p> | 2952 <h4 heading><a name="Math.min_integer"><code>Math.min_integer</code></a></h4> |
| 2950 <hr><h3><a name="pdf-math.mininteger"><code>math.mininteger</code></a></h3> | 2953 <p> |
| 2951 An integer with the minimum value for an integer. | 2954 An integer with the minimum value for an integer. |
| 2952 | 2955 |
| 2953 | 2956 |
| 2954 | 2957 |
| 2955 | 2958 |
| 2956 <p> | 2959 <h4 heading><a name="Math.modf"><code>Math.modf (x)</code></a></h4> |
| 2957 <hr><h3><a name="pdf-math.modf"><code>math.modf (x)</code></a></h3> | |
| 2958 | |
| 2959 | 2960 |
| 2960 <p> | 2961 <p> |
| 2961 Returns the integral part of <code>x</code> and the fractional part of <code>x</code>. | 2962 Returns the integral part of <code>x</code> and the fractional part of <code>x</code>. |
| 2962 Its second result is always a float. | 2963 |
| 2963 | 2964 |
| 2964 | 2965 |
| 2965 | 2966 |
| 2966 | 2967 <h4 heading><a name="Math.pi"><code>Math.pi</code></a></h4> |
| 2967 <p> | |
| 2968 <hr><h3><a name="pdf-math.pi"><code>math.pi</code></a></h3> | |
| 2969 | |
| 2970 | 2968 |
| 2971 <p> | 2969 <p> |
| 2972 The value of <em>π</em>. | 2970 The value of <em>π</em>. |
| 2973 | 2971 |
| 2974 | 2972 |
| 2975 | 2973 |
| 2976 | 2974 |
| 2977 <p> | 2975 <h4 heading><a name="Math.rad"><code>Math.rad (x)</code></a></h4> |
| 2978 <hr><h3><a name="pdf-math.rad"><code>math.rad (x)</code></a></h3> | |
| 2979 | |
| 2980 | 2976 |
| 2981 <p> | 2977 <p> |
| 2982 Converts the angle <code>x</code> from degrees to radians. | 2978 Converts the angle <code>x</code> from degrees to radians. |
| 2983 | 2979 |
| 2984 | 2980 |
| 2985 | 2981 |
| 2986 | 2982 |
| 2987 <p> | 2983 <h4 heading><a name="Math.random"><code>Math.random ([m [, n])</code></a></h4> |
| 2988 <hr><h3><a name="pdf-math.random"><code>math.random ([m [, n]])</code></a></h3> | |
| 2989 | 2984 |
| 2990 | 2985 |
| 2991 <p> | 2986 <p> |
| 2992 When called without arguments, | 2987 When called without arguments, |
| 2993 returns a pseudo-random float with uniform distribution | 2988 returns a pseudo-random float with uniform distribution |
| 2994 in the range <em>[0,1)</em>. | 2989 in the range <em>[0,1)</em>. |
| 2995 When called with two integers <code>m</code> and <code>n</code>, | 2990 When called with two integers <code>m</code> and <code>n</code>, |
| 2996 <code>math.random</code> returns a pseudo-random integer | 2991 <code>Math.random</code> returns a pseudo-random integer |
| 2997 with uniform distribution in the range <em>[m, n]</em>. | 2992 with uniform distribution in the range <em>[m, n]</em>. |
| 2998 (The value <em>m-n</em> cannot be negative and must fit in a Lua integer.) | 2993 (The value <em>m-n</em> cannot be negative and must fit in a Luan integer.) |
| 2999 The call <code>math.random(n)</code> is equivalent to <code>math.random(1,n)</code>. | 2994 The call <code>Math.random(n)</code> is equivalent to <code>Math.random(1,n)</code>. |
| 3000 | 2995 |
| 3001 | 2996 |
| 3002 <p> | 2997 <p> |
| 3003 This function is an interface to the underling | 2998 This function is an interface to the underling |
| 3004 pseudo-random generator function provided by C. | 2999 pseudo-random generator function provided by Java. |
| 3005 No guarantees can be given for its statistical properties. | 3000 No guarantees can be given for its statistical properties. |
| 3006 | 3001 |
| 3007 | 3002 |
| 3008 | 3003 |
| 3009 | 3004 |
| 3010 <p> | 3005 <h4 heading><a name="Math.sin"><code>Math.sin (x)</code></a></h4> |
| 3011 <hr><h3><a name="pdf-math.randomseed"><code>math.randomseed (x)</code></a></h3> | |
| 3012 | |
| 3013 | |
| 3014 <p> | |
| 3015 Sets <code>x</code> as the "seed" | |
| 3016 for the pseudo-random generator: | |
| 3017 equal seeds produce equal sequences of numbers. | |
| 3018 | |
| 3019 | |
| 3020 | |
| 3021 | |
| 3022 <p> | |
| 3023 <hr><h3><a name="pdf-math.sin"><code>math.sin (x)</code></a></h3> | |
| 3024 | |
| 3025 | 3006 |
| 3026 <p> | 3007 <p> |
| 3027 Returns the sine of <code>x</code> (assumed to be in radians). | 3008 Returns the sine of <code>x</code> (assumed to be in radians). |
| 3028 | 3009 |
| 3029 | 3010 |
| 3030 | 3011 |
| 3031 | 3012 |
| 3032 <p> | 3013 <h4 heading><a name="Math.sqrt"><code>Math.sqrt (x)</code></a></h4> |
| 3033 <hr><h3><a name="pdf-math.sqrt"><code>math.sqrt (x)</code></a></h3> | |
| 3034 | |
| 3035 | 3014 |
| 3036 <p> | 3015 <p> |
| 3037 Returns the square root of <code>x</code>. | 3016 Returns the square root of <code>x</code>. |
| 3038 (You can also use the expression <code>x^0.5</code> to compute this value.) | 3017 (You can also use the expression <code>x^0.5</code> to compute this value.) |
| 3039 | 3018 |
| 3040 | 3019 |
| 3041 | 3020 |
| 3042 | 3021 |
| 3043 <p> | 3022 <h4 heading><a name="Math.tan"><code>Math.tan (x)</code></a></h4> |
| 3044 <hr><h3><a name="pdf-math.tan"><code>math.tan (x)</code></a></h3> | |
| 3045 | |
| 3046 | 3023 |
| 3047 <p> | 3024 <p> |
| 3048 Returns the tangent of <code>x</code> (assumed to be in radians). | 3025 Returns the tangent of <code>x</code> (assumed to be in radians). |
| 3049 | 3026 |
| 3050 | |
| 3051 | |
| 3052 | |
| 3053 <p> | |
| 3054 <hr><h3><a name="pdf-math.tointeger"><code>math.tointeger (x)</code></a></h3> | |
| 3055 | |
| 3056 | |
| 3057 <p> | |
| 3058 If the value <code>x</code> is convertible to an integer, | |
| 3059 returns that integer. | |
| 3060 Otherwise, returns <b>nil</b>. | |
| 3061 | |
| 3062 | |
| 3063 | |
| 3064 | |
| 3065 <p> | |
| 3066 <hr><h3><a name="pdf-math.type"><code>math.type (x)</code></a></h3> | |
| 3067 | |
| 3068 | |
| 3069 <p> | |
| 3070 Returns "<code>integer</code>" if <code>x</code> is an integer, | |
| 3071 "<code>float</code>" if it is a float, | |
| 3072 or <b>nil</b> if <code>x</code> is not a number. | |
| 3073 | |
| 3074 | |
| 3075 | |
| 3076 | |
| 3077 <p> | |
| 3078 <hr><h3><a name="pdf-math.ult"><code>math.ult (m, n)</code></a></h3> | |
| 3079 | |
| 3080 | |
| 3081 <p> | |
| 3082 Returns a boolean, | |
| 3083 true if integer <code>m</code> is below integer <code>n</code> when | |
| 3084 they are compared as unsigned integers. | |
| 3085 | 3027 |
| 3086 | 3028 |
| 3087 | 3029 |
| 3088 | 3030 |
| 3089 | 3031 |
