1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310
|
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* fn-math.c: Built in mathematical functions and functions registration
*
* Authors:
* Miguel de Icaza (miguel@gnu.org)
* Jukka-Pekka Iivonen (iivonen@iki.fi)
* Morten Welinder (terra@diku.dk)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <gnumeric-config.h>
#include <glib/gi18n.h>
#include <gnumeric.h>
#include <func.h>
#include <cell.h>
#include <sheet.h>
#include <workbook.h>
#include <mathfunc.h>
#include <rangefunc.h>
#include <collect.h>
#include <value.h>
#include <expr.h>
#include <regression.h>
#include <math.h>
#include <string.h>
#include "plugin.h"
#include "plugin-util.h"
#include "module-plugin-defs.h"
GNUMERIC_MODULE_PLUGIN_INFO_DECL;
typedef struct {
GSList *list;
int num;
} math_sums_t;
static GnmValue *
callback_function_sumxy (Sheet *sheet, int col, int row,
GnmCell *cell, void *user_data)
{
math_sums_t *mm = user_data;
gnm_float x;
gpointer p;
if (cell == NULL)
return NULL;
cell_eval (cell);
switch (cell->value->type) {
case VALUE_ERROR:
return VALUE_TERMINATE;
case VALUE_BOOLEAN:
x = cell->value->v_bool.val ? 1 : 0;
break;
case VALUE_INTEGER:
x = cell->value->v_int.val;
break;
case VALUE_FLOAT:
x = cell->value->v_float.val;
break;
case VALUE_EMPTY:
default:
return NULL;
}
p = g_new (gnm_float, 1);
*((gnm_float *) p) = x;
mm->list = g_slist_append (mm->list, p);
mm->num++;
return NULL;
}
/***************************************************************************/
static char const *help_gcd = {
N_("@FUNCTION=GCD\n"
"@SYNTAX=GCD(number1,number2,...)\n"
"@DESCRIPTION="
"GCD returns the greatest common divisor of given numbers.\n"
"\n"
"* If any of the arguments is less than one, GCD returns #NUM! "
"error.\n"
"* If any of the arguments is non-integer, it is truncated.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"GCD(470,770) equals 10.\n"
"GCD(470,770,1495) equals 5.\n"
"\n"
"@SEEALSO=LCM")
};
static int
range_gcd (gnm_float const *xs, int n, gnm_float *res)
{
if (n > 0) {
int i;
int gcd_so_far = 0;
for (i = 0; i < n; i++) {
gnm_float thisx = gnumeric_fake_floor (xs[i]);
if (thisx <= 0 || thisx > INT_MAX)
return 1;
else
gcd_so_far = gcd ((int)thisx, gcd_so_far);
}
*res = gcd_so_far;
return 0;
} else
return 1;
}
static GnmValue *
gnumeric_gcd (FunctionEvalInfo *ei, GnmExprList *nodes)
{
return float_range_function (nodes, ei,
range_gcd,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_NUM);
}
/***************************************************************************/
static char const *help_lcm = {
N_("@FUNCTION=LCM\n"
"@SYNTAX=LCM(number1,number2,...)\n"
"@DESCRIPTION="
"LCM returns the least common multiple of integers. The least "
"common multiple is the smallest positive number that is a "
"multiple of all integer arguments given.\n"
"\n"
"* If any of the arguments is less than one, LCM returns #NUM!.\n"
"* If any of the arguments is non-integer, it is truncated.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"LCM(2,13) equals to 26.\n"
"LCM(4,7,5) equals to 140.\n"
"\n"
"@SEEALSO=GCD")
};
static int
range_lcm (gnm_float const *xs, int n, gnm_float *res)
{
if (n > 0) {
int i;
int lcm_so_far = 1;
for (i = 0; i < n; i++) {
gnm_float x = gnumeric_fake_floor (xs[i]);
if (x <= 0 || x > INT_MAX)
return 1;
else {
int xi = (int) x;
lcm_so_far /= gcd (lcm_so_far, xi);
lcm_so_far *= xi;
}
}
*res = lcm_so_far;
return 0;
} else
return 1;
}
static GnmValue *
gnumeric_lcm (FunctionEvalInfo *ei, GnmExprList *nodes)
{
return float_range_function (nodes, ei,
range_lcm,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_NUM);
}
/***************************************************************************/
static char const *help_hypot = {
N_("@FUNCTION=HYPOT\n"
"@SYNTAX=HYPOT(number1,number2,...)\n"
"@DESCRIPTION="
"HYPOT returns the square root of the sum of the squares of the arguments.\n"
"\n"
"@EXAMPLES=\n"
"HYPOT(3,4) equals to 5.\n"
"\n"
"@SEEALSO=MIN,MAX")
};
static GnmValue *
gnumeric_hypot (FunctionEvalInfo *ei, GnmExprList *nodes)
{
return float_range_function (nodes, ei,
range_hypot,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_NUM);
}
/***************************************************************************/
static char const *help_abs = {
N_("@FUNCTION=ABS\n"
"@SYNTAX=ABS(b1)\n"
"@DESCRIPTION="
"ABS implements the Absolute Value function: the result is "
"to drop the negative sign (if present). This can be done for "
"integers and floating point numbers.\n\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"ABS(7) equals 7.\n"
"ABS(-3.14) equals 3.14.\n"
"\n"
"@SEEALSO=CEIL, CEILING, FLOOR, INT, MOD")
};
static GnmValue *
gnumeric_abs (FunctionEvalInfo *ei, GnmValue **args)
{
return value_new_float (gnumabs (value_get_as_float (args [0])));
}
/***************************************************************************/
static char const *help_acos = {
N_("@FUNCTION=ACOS\n"
"@SYNTAX=ACOS(x)\n"
"@DESCRIPTION="
"ACOS function calculates the arc cosine of @x; that "
"is the value whose cosine is @x.\n"
"\n"
"* The value it returns is in radians.\n"
"* If @x falls outside the range -1 to 1, ACOS returns "
"the #NUM! error.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"ACOS(0.1) equals 1.470629.\n"
"ACOS(-0.1) equals 1.670964.\n"
"\n"
"@SEEALSO=COS, SIN, DEGREES, RADIANS")
};
static GnmValue *
gnumeric_acos (FunctionEvalInfo *ei, GnmValue **args)
{
gnm_float t;
t = value_get_as_float (args [0]);
if ((t < -1.0) || (t > 1.0))
return value_new_error_NUM (ei->pos);
return value_new_float (acosgnum (t));
}
/***************************************************************************/
static char const *help_acosh = {
N_("@FUNCTION=ACOSH\n"
"@SYNTAX=ACOSH(x)\n"
"@DESCRIPTION="
"ACOSH function calculates the inverse hyperbolic "
"cosine of @x; that is the value whose hyperbolic cosine is "
"@x.\n"
"\n"
"* If @x is less than 1.0, ACOSH() returns the #NUM! error.\n"
"* This function is Excel compatible.\n "
"\n"
"@EXAMPLES=\n"
"ACOSH(2) equals 1.31696.\n"
"ACOSH(5.3) equals 2.35183.\n"
"\n"
"@SEEALSO=ACOS, ASINH, DEGREES, RADIANS ")
};
static GnmValue *
gnumeric_acosh (FunctionEvalInfo *ei, GnmValue **args)
{
gnm_float t;
t = value_get_as_float (args [0]);
if (t < 1.0)
return value_new_error_NUM (ei->pos);
return value_new_float (acoshgnum (t));
}
/***************************************************************************/
static char const *help_asin = {
N_("@FUNCTION=ASIN\n"
"@SYNTAX=ASIN(x)\n"
"@DESCRIPTION="
"ASIN function calculates the arc sine of @x; that is "
"the value whose sine is @x.\n"
"\n"
"* If @x falls outside the range -1 to 1, ASIN returns "
"the #NUM! error.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"ASIN(0.5) equals 0.523599.\n"
"ASIN(1) equals 1.570797.\n"
"\n"
"@SEEALSO=SIN, COS, ASINH, DEGREES, RADIANS")
};
static GnmValue *
gnumeric_asin (FunctionEvalInfo *ei, GnmValue **args)
{
gnm_float t;
t = value_get_as_float (args [0]);
if ((t < -1.0) || (t > 1.0))
return value_new_error_NUM (ei->pos);
return value_new_float (asingnum (t));
}
/***************************************************************************/
static char const *help_asinh = {
N_("@FUNCTION=ASINH\n"
"@SYNTAX=ASINH(x)\n"
"@DESCRIPTION="
"ASINH function calculates the inverse hyperbolic sine of @x; "
"that is the value whose hyperbolic sine is @x.\n\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"ASINH(0.5) equals 0.481212.\n"
"ASINH(1.0) equals 0.881374.\n"
"\n"
"@SEEALSO=ASIN, ACOSH, SIN, COS, DEGREES, RADIANS")
};
static GnmValue *
gnumeric_asinh (FunctionEvalInfo *ei, GnmValue **args)
{
return value_new_float (asinhgnum (value_get_as_float (args [0])));
}
/***************************************************************************/
static char const *help_atan = {
N_("@FUNCTION=ATAN\n"
"@SYNTAX=ATAN(x)\n"
"@DESCRIPTION="
"ATAN function calculates the arc tangent of @x; that "
"is the value whose tangent is @x.\n\n"
"* Return value is in radians.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"ATAN(0.5) equals 0,463648.\n"
"ATAN(1) equals 0,785398.\n"
"\n"
"@SEEALSO=TAN, COS, SIN, DEGREES, RADIANS")
};
static GnmValue *
gnumeric_atan (FunctionEvalInfo *ei, GnmValue **args)
{
return value_new_float (atangnum (value_get_as_float (args [0])));
}
/***************************************************************************/
static char const *help_atanh = {
N_("@FUNCTION=ATANH\n"
"@SYNTAX=ATANH(x)\n"
"@DESCRIPTION="
"ATANH function calculates the inverse hyperbolic tangent "
"of @x; that is the value whose hyperbolic tangent is @x.\n"
"\n"
"* If the absolute value of @x is greater than 1.0, ATANH "
"returns #NUM! error.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"ATANH(0.5) equals 0.549306.\n"
"ATANH(0.8) equals 1.098612.\n"
"\n"
"@SEEALSO=ATAN, TAN, SIN, COS, DEGREES, RADIANS")
};
static GnmValue *
gnumeric_atanh (FunctionEvalInfo *ei, GnmValue **args)
{
gnm_float t;
t = value_get_as_float (args [0]);
if ((t <= -1.0) || (t >= 1.0))
return value_new_error_NUM (ei->pos);
return value_new_float (atanhgnum (value_get_as_float (args [0])));
}
/***************************************************************************/
static char const *help_atan2 = {
N_("@FUNCTION=ATAN2\n"
"@SYNTAX=ATAN2(b1,b2)\n"
"@DESCRIPTION="
"ATAN2 function calculates the arc tangent of the two "
"variables @b1 and @b2. It is similar to calculating the arc "
"tangent of @b2 / @b1, except that the signs of both arguments "
"are used to determine the quadrant of the result.\n\n"
"* The result is in radians.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"ATAN2(0.5,1.0) equals 1.107149.\n"
"ATAN2(-0.5,2.0) equals 1.815775.\n"
"\n"
"@SEEALSO=ATAN, ATANH, COS, SIN, DEGREES, RADIANS")
};
static GnmValue *
gnumeric_atan2 (FunctionEvalInfo *ei, GnmValue **args)
{
return value_new_float (atan2gnum (value_get_as_float (args [1]),
value_get_as_float (args [0])));
}
/***************************************************************************/
static char const *help_ceil = {
N_("@FUNCTION=CEIL\n"
"@SYNTAX=CEIL(x)\n"
"@DESCRIPTION="
"CEIL function rounds @x up to the next nearest integer.\n\n"
"\n"
"@EXAMPLES=\n"
"CEIL(0.4) equals 1.\n"
"CEIL(-1.1) equals -1.\n"
"CEIL(-2.9) equals -2.\n"
"\n"
"@SEEALSO=CEILING, FLOOR, ABS, INT, MOD")
};
static GnmValue *
gnumeric_ceil (FunctionEvalInfo *ei, GnmValue **args)
{
return value_new_float (gnumeric_fake_ceil
(value_get_as_float (args [0])));
}
/***************************************************************************/
static char const *help_countif = {
N_("@FUNCTION=COUNTIF\n"
"@SYNTAX=COUNTIF(range,criteria)\n"
"@DESCRIPTION="
"COUNTIF function counts the number of cells in the given @range "
"that meet the given @criteria.\n\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"Let us assume that the cells A1, A2, ..., A5 contain numbers "
"23, 27, 28, 33, and 39. Then\n"
"COUNTIF(A1:A5,\"<=28\") equals 3.\n"
"COUNTIF(A1:A5,\"<28\") equals 2.\n"
"COUNTIF(A1:A5,\"28\") equals 1.\n"
"COUNTIF(A1:A5,\">28\") equals 2.\n"
"\n"
"@SEEALSO=COUNT,SUMIF")
};
typedef struct {
criteria_test_fun_t test;
GnmValue *test_value;
unsigned int count;
} CountIfClosure;
static GnmValue *
cb_countif (Sheet *sheet, int col, int row, GnmCell *cell,
CountIfClosure *res)
{
if (cell == NULL)
return NULL;
cell_eval (cell);
switch (cell->value->type) {
case VALUE_BOOLEAN: case VALUE_INTEGER: case VALUE_FLOAT:
case VALUE_STRING:
if ((res->test) (cell->value, res->test_value))
res->count++;
default: break;
}
return NULL;
}
static GnmValue *
gnumeric_countif (FunctionEvalInfo *ei, GnmValue **argv)
{
GnmValueRange const *r = &argv[0]->v_range;
Sheet *sheet;
GnmValue *problem;
CellIterFlags iter_flags;
CountIfClosure res;
/* XL has some limitations on @range that we currently emulate, but do
* not need to.
* 1) @range must be a range, arrays are not supported
* 2) @range can not be 3d */
if (r->type != VALUE_CELLRANGE ||
((sheet = eval_sheet (r->cell.a.sheet, ei->pos->sheet)) != r->cell.b.sheet &&
r->cell.b.sheet != NULL) ||
(!VALUE_IS_NUMBER (argv[1]) && argv[1]->type != VALUE_STRING))
return value_new_error_VALUE (ei->pos);
res.count = 0;
parse_criteria (argv[1], &res.test, &res.test_value, &iter_flags,
workbook_date_conv (ei->pos->sheet->workbook));
problem = sheet_foreach_cell_in_range (sheet, iter_flags,
r->cell.a.col, r->cell.a.row, r->cell.b.col, r->cell.b.row,
(CellIterFunc) &cb_countif, &res);
value_release (res.test_value);
if (NULL != problem)
return value_new_error_VALUE (ei->pos);
return value_new_int (res.count);
}
/***************************************************************************/
static char const *help_sumif = {
N_("@FUNCTION=SUMIF\n"
"@SYNTAX=SUMIF(range,criteria[,actual_range])\n"
"@DESCRIPTION="
"SUMIF function sums the values in the given @range that meet "
"the given @criteria. If @actual_range is given, SUMIF sums "
"the values in the @actual_range whose corresponding components "
"in @range meet the given @criteria.\n\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"Let us assume that the cells A1, A2, ..., A5 contain numbers "
"23, 27, 28, 33, and 39. Then\n"
"SUMIF(A1:A5,\"<=28\") equals 78.\n"
"SUMIF(A1:A5,\"<28\") equals 50.\n"
"In addition, if the cells B1, B2, ..., B5 hold numbers "
"5, 3, 2, 6, and 7 then:\n"
"SUMIF(A1:A5,\"<=27\",B1:B5) equals 8.\n"
"\n"
"@SEEALSO=COUNTIF, SUM")
};
typedef struct {
criteria_test_fun_t test;
GnmValue *test_value;
Sheet *target_sheet;
GnmCellPos offset;
gnm_float sum;
} SumIfClosure;
static GnmValue *
cb_sumif (Sheet *sheet, int col, int row, GnmCell *cell,
SumIfClosure *res)
{
if (cell == NULL)
return NULL;
cell_eval (cell);
switch (cell->value->type) {
case VALUE_BOOLEAN: case VALUE_INTEGER: case VALUE_FLOAT:
case VALUE_STRING:
if ((res->test) (cell->value, res->test_value)) {
if (NULL != res->target_sheet) {
cell = sheet_cell_get (res->target_sheet,
col + res->offset.col, row + res->offset.row);
if (cell != NULL) {
cell_eval (cell);
switch (cell->value->type) {
case VALUE_INTEGER: res->sum += cell->value->v_int.val; break;
case VALUE_FLOAT: res->sum += cell->value->v_float.val; break;
default : break;
}
}
} else
res->sum += value_get_as_float (cell->value);
}
default:
break;
}
return NULL;
}
static GnmValue *
gnumeric_sumif (FunctionEvalInfo *ei, GnmValue **argv)
{
GnmValueRange const *r = &argv[0]->v_range;
Sheet *sheet;
GnmValue *problem;
CellIterFlags iter_flags;
SumIfClosure res;
int tmp, col_end, row_end;
/* XL has some limitations on @range that we currently emulate, but do
* not need to.
* 1) @range must be a range, arrays are not supported
* 2) @range can not be 3d */
if (r->type != VALUE_CELLRANGE ||
((sheet = eval_sheet (r->cell.a.sheet, ei->pos->sheet)) != r->cell.b.sheet &&
r->cell.b.sheet != NULL) ||
(!VALUE_IS_NUMBER (argv[1]) && argv[1]->type != VALUE_STRING))
return value_new_error_VALUE (ei->pos);
col_end = r->cell.b.col;
row_end = r->cell.b.row;
if (NULL != argv[2]) {
GnmValueRange const *target = &argv[2]->v_range;
res.target_sheet = eval_sheet (target->cell.a.sheet, ei->pos->sheet);
if (res.target_sheet != eval_sheet (target->cell.b.sheet, ei->pos->sheet))
return value_new_error_VALUE (ei->pos);
res.offset.col = target->cell.a.col - r->cell.a.col;
res.offset.row = target->cell.a.row - r->cell.a.row;
/* no need to search items with no value */
tmp = target->cell.b.col - target->cell.a.col;
if (tmp < (r->cell.b.col - r->cell.a.col))
col_end = r->cell.a.col + tmp;
tmp = target->cell.b.row - target->cell.a.row;
if (tmp < (r->cell.b.row - r->cell.a.row))
row_end = r->cell.a.row + tmp;
} else
res.target_sheet = NULL;
res.sum = 0.;
parse_criteria (argv[1], &res.test, &res.test_value, &iter_flags,
workbook_date_conv (ei->pos->sheet->workbook));
problem = sheet_foreach_cell_in_range (sheet, iter_flags,
r->cell.a.col, r->cell.a.row, col_end, row_end,
(CellIterFunc) &cb_sumif, &res);
value_release (res.test_value);
if (NULL != problem)
return value_new_error_VALUE (ei->pos);
return value_new_float (res.sum);
}
/***************************************************************************/
static char const *help_ceiling = {
N_("@FUNCTION=CEILING\n"
"@SYNTAX=CEILING(x,significance)\n"
"@DESCRIPTION="
"CEILING function rounds @x up to the nearest multiple of "
"@significance.\n"
"\n"
"* If @x or @significance is non-numeric CEILING returns "
"#VALUE! error.\n"
"* If @x and @significance have different signs CEILING returns "
"#NUM! error.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"CEILING(2.43,1) equals 3.\n"
"CEILING(123.123,3) equals 126.\n"
"\n"
"@SEEALSO=CEIL, FLOOR, ABS, INT, MOD")
};
static GnmValue *
gnumeric_ceiling (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float number = value_get_as_float (argv[0]);
gnm_float s;
if (argv[1] == NULL)
s = (number >= 0) ? 1.0 : -1.0;
else {
s = value_get_as_float (argv[1]);
}
if (number == 0)
return value_new_int (0);
if (s == 0)
return value_new_error_DIV0 (ei->pos);
if (number / s < 0)
return value_new_error_NUM (ei->pos);
return value_new_float (gnumeric_fake_ceil (number / s) * s);
}
/***************************************************************************/
static char const *help_cos = {
N_("@FUNCTION=COS\n"
"@SYNTAX=COS(x)\n"
"@DESCRIPTION="
"COS function returns the cosine of @x, where @x is given "
"in radians.\n\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"COS(0.5) equals 0.877583.\n"
"COS(1) equals 0.540302.\n"
"\n"
"@SEEALSO=COSH, SIN, SINH, TAN, TANH, RADIANS, DEGREES")
};
static GnmValue *
gnumeric_cos (FunctionEvalInfo *ei, GnmValue **argv)
{
return value_new_float (cosgnum (value_get_as_float (argv [0])));
}
/***************************************************************************/
static char const *help_cosh = {
N_("@FUNCTION=COSH\n"
"@SYNTAX=COSH(x)\n"
"@DESCRIPTION="
"COSH function returns the hyperbolic cosine of @x, which "
"is defined mathematically as\n\n\t(exp(@x) + exp(-@x)) / 2.\n\n"
"* @x is in radians.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"COSH(0.5) equals 1.127626.\n"
"COSH(1) equals 1.543081.\n"
"\n"
"@SEEALSO=COS, SIN, SINH, TAN, TANH, RADIANS, DEGREES, EXP")
};
static GnmValue *
gnumeric_cosh (FunctionEvalInfo *ei, GnmValue **argv)
{
return value_new_float (coshgnum (value_get_as_float (argv [0])));
}
/***************************************************************************/
static char const *help_degrees = {
N_("@FUNCTION=DEGREES\n"
"@SYNTAX=DEGREES(x)\n"
"@DESCRIPTION="
"DEGREES computes the number of degrees equivalent to @x radians.\n"
"\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"DEGREES(2.5) equals 143.2394.\n"
"\n"
"@SEEALSO=RADIANS, PI")
};
static GnmValue *
gnumeric_degrees (FunctionEvalInfo *ei, GnmValue **argv)
{
return value_new_float ((value_get_as_float (argv [0]) * 180.0) /
M_PIgnum);
}
/***************************************************************************/
static char const *help_exp = {
N_("@FUNCTION=EXP\n"
"@SYNTAX=EXP(x)\n"
"@DESCRIPTION="
"EXP computes the value of e (the base of natural logarithms) "
"raised to the power of @x.\n\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"EXP(2) equals 7.389056.\n"
"\n"
"@SEEALSO=LOG, LOG2, LOG10")
};
static GnmValue *
gnumeric_exp (FunctionEvalInfo *ei, GnmValue **argv)
{
return value_new_float (expgnum (value_get_as_float (argv [0])));
}
/***************************************************************************/
static char const *help_expm1 = {
N_("@FUNCTION=EXPM1\n"
"@SYNTAX=EXPM1(x)\n"
"@DESCRIPTION="
"EXPM1 computes EXP(@x)-1 with higher resulting precision than "
"the direct formula.\n\n"
"@EXAMPLES=\n"
"EXPM1(0.01) equals 0.01005.\n"
"\n"
"@SEEALSO=EXP, LN1P")
};
static GnmValue *
gnumeric_expm1 (FunctionEvalInfo *ei, GnmValue **argv)
{
return value_new_float (expm1gnum (value_get_as_float (argv [0])));
}
/***************************************************************************/
static char const *help_fact = {
N_("@FUNCTION=FACT\n"
"@SYNTAX=FACT(x)\n"
"@DESCRIPTION="
"FACT computes the factorial of @x. ie, @x!\n\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"FACT(3) equals 6.\n"
"FACT(9) equals 362880.\n"
"\n"
"@SEEALSO=")
};
static GnmValue *
gnumeric_fact (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float x = value_get_as_float (argv[0]);
gboolean x_is_integer = (x == floorgnum (x));
if (x < 0 && x_is_integer)
return value_new_error_NUM (ei->pos);
if (x > 12 || !x_is_integer) {
int sign;
gnm_float tmp = lgamma_rgnum (x + 1, &sign);
gnm_float res = sign * expgnum (tmp);
if (x_is_integer)
res = floorgnum (res + 0.5); /* Round, just in case. */
return value_new_float (res);
} else
return value_new_int (fact (x));
}
/***************************************************************************/
static char const *help_beta = {
N_("@FUNCTION=BETA\n"
"@SYNTAX=BETA(a,b)\n"
"@DESCRIPTION="
"BETA function returns the value of the mathematic beta function "
"extended to all real numbers except 0 and negative integers.\n"
"\n"
"* If @a, @b, or (@a + @b) are non-positive integers, BETA returns #NUM! "
"error.\n"
"\n"
"@EXAMPLES=\n"
"BETA(2,3) equals 0.083333.\n"
"BETA(-0.5,0.5) equals #NUM!.\n"
"\n"
"@SEEALSO=BETALN,GAMMALN")
};
static GnmValue *
gnumeric_beta (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float a = value_get_as_float (argv[0]);
gnm_float b = value_get_as_float (argv[1]);
#warning "Improve error handling. Relying on value_new_float to do it is cheesy"
return value_new_float (beta (a, b));
}
/***************************************************************************/
static char const *help_betaln = {
N_("@FUNCTION=BETALN\n"
"@SYNTAX=BETALN(a,b)\n"
"@DESCRIPTION="
"BETALN function returns the natural logarithm of the "
"absolute value of the beta function.\n"
"\n"
"* If @a, @b, or (@a + @b) are non-positive integers, BETALN returns #NUM! "
"\n"
"@EXAMPLES=\n"
"BETALN(2,3) equals -2.48.\n"
"BETALN(-0.5,0.5) equals #NUM!.\n"
"\n"
"@SEEALSO=BETA,GAMMALN")
};
static GnmValue *
gnumeric_betaln (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float a = value_get_as_float (argv[0]);
gnm_float b = value_get_as_float (argv[1]);
int sign;
return value_new_float (lbeta3 (a, b, &sign));
}
/***************************************************************************/
static char const *help_combin = {
N_("@FUNCTION=COMBIN\n"
"@SYNTAX=COMBIN(n,k)\n"
"@DESCRIPTION="
"COMBIN computes the number of combinations.\n"
"\n"
"* Performing this function on a non-integer or a negative number "
"returns #NUM! error.\n"
"* If @n is less than @k COMBIN returns #NUM! error.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"COMBIN(8,6) equals 28.\n"
"COMBIN(6,2) equals 15.\n"
"\n"
"@SEEALSO=")
};
static GnmValue *
gnumeric_combin (FunctionEvalInfo *ei, GnmValue **argv)
{
int n = value_get_as_int (argv[0]);
int k = value_get_as_int (argv[1]);
if (k >= 0 && n >= k)
return value_new_float (combin (n ,k));
return value_new_error_NUM (ei->pos);
}
/***************************************************************************/
static char const *help_floor = {
N_("@FUNCTION=FLOOR\n"
"@SYNTAX=FLOOR(x[,significance])\n"
"@DESCRIPTION="
"FLOOR function rounds @x down to the next nearest multiple "
"of @significance.\n\n"
"* @significance defaults to 1.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"FLOOR(0.5) equals 0.\n"
"FLOOR(5,2) equals 4.\n"
"FLOOR(-5,-2) equals -4.\n"
"FLOOR(-5,2) equals #NUM!.\n"
"\n"
"@SEEALSO=CEIL, CEILING, ABS, INT, MOD")
};
static GnmValue *
gnumeric_floor (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float number, s;
number = value_get_as_float (argv[0]);
if (argv[1] == NULL)
s = (number >= 0) ? 1.0 : -1.0;
else
s = value_get_as_float (argv[1]);
if (number == 0)
return value_new_int (0);
if (s == 0)
return value_new_error_DIV0 (ei->pos);
if (number / s < 0)
return value_new_error_NUM (ei->pos);
return value_new_float (gnumeric_fake_floor (number / s) * s);
}
/***************************************************************************/
static char const *help_int = {
N_("@FUNCTION=INT\n"
"@SYNTAX=INT(a)\n"
"@DESCRIPTION="
"INT function returns the largest integer that is not "
"bigger than its argument.\n\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"INT(7.2) equals 7.\n"
"INT(-5.5) equals -6.\n"
"\n"
"@SEEALSO=CEIL, CEILING, FLOOR, ABS, MOD")
};
static GnmValue *
gnumeric_int (FunctionEvalInfo *ei, GnmValue **argv)
{
return value_new_float (gnumeric_fake_floor
(value_get_as_float (argv [0])));
}
/***************************************************************************/
static char const *help_log = {
N_("@FUNCTION=LOG\n"
"@SYNTAX=LOG(x[,base])\n"
"@DESCRIPTION="
"LOG computes the logarithm of @x in the given base @base. "
"If no @base is given LOG returns the logarithm in base 10. "
"@base must be > 0. and cannot equal 1.\n\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"LOG(2) equals 0.30103.\n"
"LOG(8192,2) equals 13.\n"
"\n"
"@SEEALSO=LN, LOG2, LOG10")
};
static GnmValue *
gnumeric_log (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float t = value_get_as_float (argv [0]);
gnm_float base = argv[1] ? value_get_as_float (argv[1]) : 10;
if (base == 1. || base <= 0.)
return value_new_error_NUM (ei->pos);
if (t <= 0.0)
return value_new_error_NUM (ei->pos);
return value_new_float (loggnum (t) / loggnum (base));
}
/***************************************************************************/
static char const *help_ln = {
N_("@FUNCTION=LN\n"
"@SYNTAX=LN(x)\n"
"@DESCRIPTION="
"LN returns the natural logarithm of @x.\n"
"\n"
"* If @x <= 0, LN returns #NUM! error.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"LN(7) equals 1.94591.\n"
"\n"
"@SEEALSO=EXP, LOG2, LOG10")
};
static GnmValue *
gnumeric_ln (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float t = value_get_as_float (argv [0]);
if (t <= 0.0)
return value_new_error_NUM (ei->pos);
return value_new_float (loggnum (t));
}
/***************************************************************************/
static char const *help_ln1p = {
N_("@FUNCTION=LN1P\n"
"@SYNTAX=LN1P(x)\n"
"@DESCRIPTION="
"LN1P computes LN(1+@x) with higher resulting precision than "
"the direct formula.\n"
"\n"
"* If @x <= -1, LN1P returns #NUM! error.\n"
"\n"
"@EXAMPLES=\n"
"LN1P(0.01) equals 0.00995.\n"
"\n"
"@SEEALSO=LN, EXPM1")
};
static GnmValue *
gnumeric_ln1p (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float t = value_get_as_float (argv [0]);
if (t <= -1)
return value_new_error_NUM (ei->pos);
return value_new_float (log1pgnum (t));
}
/***************************************************************************/
static char const *help_power = {
N_("@FUNCTION=POWER\n"
"@SYNTAX=POWER(x,y)\n"
"@DESCRIPTION="
"POWER returns the value of @x raised to the power @y.\n\n"
"\n"
"* If both @x and @y equals to 0, POWER returns #NUM! error.\n"
"* If @x = 0 and @y < 0, POWER returns #DIV/0! error.\n"
"* If @x < 0 and @y is non-integer, POWER returns #NUM! error.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"POWER(2,7) equals 128.\n"
"POWER(3,3.141) equals 31.523749.\n"
"\n"
"@SEEALSO=EXP")
};
static GnmValue *
gnumeric_power (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float x = value_get_as_float (argv [0]);
gnm_float y = value_get_as_float (argv [1]);
if ((x > 0) || (x == 0 && y > 0) || (x < 0 && y == floorgnum (y)))
return value_new_float (powgnum (x, y));
if (x == 0 && y != 0)
return value_new_error_DIV0 (ei->pos);
else
return value_new_error_NUM (ei->pos);
}
/***************************************************************************/
static char const *help_log2 = {
N_("@FUNCTION=LOG2\n"
"@SYNTAX=LOG2(x)\n"
"@DESCRIPTION="
"LOG2 computes the base-2 logarithm of @x.\n\n"
"* If @x <= 0, LOG2 returns #NUM! error.\n"
"\n"
"@EXAMPLES=\n"
"LOG2(1024) equals 10.\n"
"\n"
"@SEEALSO=EXP, LOG10, LOG")
};
static GnmValue *
gnumeric_log2 (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float t = value_get_as_float (argv [0]);
if (t <= 0.0)
return value_new_error_NUM (ei->pos);
return value_new_float (loggnum (t) / M_LN2gnum);
}
/***************************************************************************/
static char const *help_log10 = {
N_("@FUNCTION=LOG10\n"
"@SYNTAX=LOG10(x)\n"
"@DESCRIPTION="
"LOG10 computes the base-10 logarithm of @x.\n\n"
"* If @x <= 0, LOG10 returns #NUM! error.\n"
"* This function is Excel compatible.\n "
"\n"
"@EXAMPLES=\n"
"LOG10(7) equals 0.845098.\n"
"\n"
"@SEEALSO=EXP, LOG2, LOG")
};
static GnmValue *
gnumeric_log10 (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float t;
t = value_get_as_float (argv [0]);
if (t <= 0.0)
return value_new_error_NUM (ei->pos);
return value_new_float (log10gnum (t));
}
/***************************************************************************/
static char const *help_mod = {
N_("@FUNCTION=MOD\n"
"@SYNTAX=MOD(number,divisor)\n"
"@DESCRIPTION="
"MOD function returns the remainder when @divisor is divided "
"into @number.\n"
"\n"
"* MOD returns #DIV/0! if @divisor is zero.\n"
"* This function is Excel compatible.\n "
"\n"
"@EXAMPLES=\n"
"MOD(23,7) equals 2.\n"
"\n"
"@SEEALSO=CEIL, CEILING, FLOOR, ABS, INT, ABS")
};
/*
* MOD(-1,-3) = -1
* MOD(2,-3) = -2
* MOD(10.6,2) = 0.6
* MOD(-10.6,2) = 1.4
* MOD(10.6,-2) = -0.6
* MOD(-10.6,-2) = -1.4
*/
static GnmValue *
gnumeric_mod (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float a, b, babs, r;
a = value_get_as_float (argv[0]);
b = value_get_as_float (argv[1]);
if (b == 0)
return value_new_error_DIV0 (ei->pos);
babs = gnumabs (b);
r = fmodgnum (gnumabs (a), babs);
if (r > 0) {
if ((a < 0) != (b < 0))
r = babs - r;
if (b < 0)
r = -r;
}
return value_new_float (r);
}
/***************************************************************************/
static char const *help_radians = {
N_("@FUNCTION=RADIANS\n"
"@SYNTAX=RADIANS(x)\n"
"@DESCRIPTION="
"RADIANS computes the number of radians equivalent to @x degrees.\n"
"\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"RADIANS(180) equals 3.14159.\n"
"\n"
"@SEEALSO=PI,DEGREES")
};
static GnmValue *
gnumeric_radians (FunctionEvalInfo *ei, GnmValue **argv)
{
return value_new_float ((value_get_as_float (argv [0]) * M_PIgnum) /
180);
}
/***************************************************************************/
static char const *help_sin = {
N_("@FUNCTION=SIN\n"
"@SYNTAX=SIN(x)\n"
"@DESCRIPTION="
"SIN function returns the sine of @x, where @x is given "
"in radians.\n\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"SIN(0.5) equals 0.479426.\n"
"\n"
"@SEEALSO=COS, COSH, SINH, TAN, TANH, RADIANS, DEGREES")
};
static GnmValue *
gnumeric_sin (FunctionEvalInfo *ei, GnmValue **argv)
{
return value_new_float (singnum (value_get_as_float (argv [0])));
}
/***************************************************************************/
static char const *help_sinh = {
N_("@FUNCTION=SINH\n"
"@SYNTAX=SINH(x)\n"
"@DESCRIPTION="
"SINH function returns the hyperbolic sine of @x, "
"which is defined mathematically as\n\n\t"
"(exp(@x) - exp(-@x)) / 2.\n\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"SINH(0.5) equals 0.521095.\n"
"\n"
"@SEEALSO=SIN, COS, COSH, TAN, TANH, DEGREES, RADIANS, EXP")
};
static GnmValue *
gnumeric_sinh (FunctionEvalInfo *ei, GnmValue **argv)
{
return value_new_float (sinhgnum (value_get_as_float (argv [0])));
}
/***************************************************************************/
static char const *help_sqrt = {
N_("@FUNCTION=SQRT\n"
"@SYNTAX=SQRT(x)\n"
"@DESCRIPTION="
"SQRT function returns the square root of @x.\n"
"\n"
"* If @x is negative, SQRT returns #NUM! error.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"SQRT(2) equals 1.4142136.\n"
"\n"
"@SEEALSO=POWER")
};
static GnmValue *
gnumeric_sqrt (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float x = value_get_as_float (argv[0]);
if (x < 0)
return value_new_error_NUM (ei->pos);
return value_new_float (sqrtgnum (x));
}
/***************************************************************************/
static char const *help_suma = {
N_("@FUNCTION=SUMA\n"
"@SYNTAX=SUMA(value1, value2, ...)\n"
"@DESCRIPTION="
"SUMA computes the sum of all the values and cells referenced "
"in the argument list. Numbers, text and logical values are "
"included in the calculation too. If the cell contains text or "
"the argument evaluates to FALSE, it is counted as value zero (0). "
"If the argument evaluates to TRUE, it is counted as one (1).\n"
"\n"
"@EXAMPLES=\n"
"Let us assume that the cells A1, A2, ..., A5 contain numbers "
"11, 15, 17, 21, and 43. Then\n"
"SUMA(A1:A5) equals 107.\n"
"\n"
"@SEEALSO=AVERAGE, SUM, COUNT")
};
static GnmValue *
gnumeric_suma (FunctionEvalInfo *ei, GnmExprList *nodes)
{
return float_range_function (nodes, ei,
range_sum,
COLLECT_ZERO_STRINGS |
COLLECT_ZEROONE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_VALUE);
}
/***************************************************************************/
static char const *help_sumsq = {
N_("@FUNCTION=SUMSQ\n"
"@SYNTAX=SUMSQ(value1, value2, ...)\n"
"@DESCRIPTION="
"SUMSQ returns the sum of the squares of all the values and "
"cells referenced in the argument list.\n\n"
"* This function is Excel compatible.\n "
"\n"
"@EXAMPLES=\n"
"Let us assume that the cells A1, A2, ..., A5 contain numbers "
"11, 15, 17, 21, and 43. Then\n"
"SUMSQ(A1:A5) equals 2925.\n"
"\n"
"@SEEALSO=SUM, COUNT")
};
static GnmValue *
gnumeric_sumsq (FunctionEvalInfo *ei, GnmExprList *nodes)
{
return float_range_function (nodes, ei,
range_sumsq,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_VALUE);
}
/***************************************************************************/
static char const *help_multinomial = {
N_("@FUNCTION=MULTINOMIAL\n"
"@SYNTAX=MULTINOMIAL(value1, value2, ...)\n"
"@DESCRIPTION="
"MULTINOMIAL returns the ratio of the factorial of a sum of "
"values to the product of factorials.\n\n"
"* This function is Excel compatible.\n "
"\n"
"@EXAMPLES=\n"
"MULTINOMIAL(2,3,4) equals 1260.\n"
"\n"
"@SEEALSO=SUM")
};
static GnmValue *
gnumeric_multinomial (FunctionEvalInfo *ei, GnmExprList *nodes)
{
return float_range_function (nodes, ei,
range_multinomial,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_NUM);
}
/***************************************************************************/
static char const *help_g_product = {
N_("@FUNCTION=G_PRODUCT\n"
"@SYNTAX=G_PRODUCT(value1, value2, ...)\n"
"@DESCRIPTION="
"G_PRODUCT returns the product of all the values and cells "
"referenced in the argument list.\n\n"
"* Empty cells are ignored and the empty product is 1.\n"
"\n"
"@EXAMPLES=\n"
"G_PRODUCT(2,5,9) equals 90.\n"
"\n"
"@SEEALSO=SUM, COUNT")
};
static GnmValue *
gnumeric_g_product (FunctionEvalInfo *ei, GnmExprList *nodes)
{
return float_range_function (nodes, ei,
range_product,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_VALUE);
}
/***************************************************************************/
static char const *help_tan = {
N_("@FUNCTION=TAN\n"
"@SYNTAX=TAN(x)\n"
"@DESCRIPTION="
"TAN function returns the tangent of @x, where @x is "
"given in radians.\n\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"TAN(3) equals -0.1425465.\n"
"\n"
"@SEEALSO=TANH, COS, COSH, SIN, SINH, DEGREES, RADIANS")
};
static GnmValue *
gnumeric_tan (FunctionEvalInfo *ei, GnmValue **argv)
{
return value_new_float (tangnum (value_get_as_float (argv [0])));
}
/***************************************************************************/
static char const *help_tanh = {
N_("@FUNCTION=TANH\n"
"@SYNTAX=TANH(x)\n"
"@DESCRIPTION="
"TANH function returns the hyperbolic tangent of @x, "
"which is defined mathematically as \n\n\tsinh(@x) / cosh(@x).\n\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"TANH(2) equals 0.96402758.\n"
"\n"
"@SEEALSO=TAN, SIN, SINH, COS, COSH, DEGREES, RADIANS")
};
static GnmValue *
gnumeric_tanh (FunctionEvalInfo *ei, GnmValue **argv)
{
return value_new_float (tanhgnum (value_get_as_float (argv [0])));
}
/***************************************************************************/
static char const *help_pi = {
N_("@FUNCTION=PI\n"
"@SYNTAX=PI()\n"
"@DESCRIPTION="
"PI functions returns the value of pi.\n"
"\n"
"* This function is called with no arguments.\n"
"* This function is Excel compatible, except that "
"it returns pi with a better precision.\n"
"\n"
"@EXAMPLES=\n"
"PI() equals about 3.141593.\n"
"\n"
"@SEEALSO=SQRTPI")
};
static GnmValue *
gnumeric_pi (FunctionEvalInfo *ei, GnmValue **argv)
{
return value_new_float (M_PIgnum);
}
/***************************************************************************/
static char const *help_trunc = {
N_("@FUNCTION=TRUNC\n"
"@SYNTAX=TRUNC(number[,digits])\n"
"@DESCRIPTION="
"TRUNC function returns the value of @number "
"truncated to the number of digits specified.\n\n"
"* If @digits is omitted or negative then @digits defaults to zero.\n"
"* If @digits is not an integer, it is truncated.\n"
"* This function is Excel compatible.\n "
"\n"
"@EXAMPLES=\n"
"TRUNC(3.12) equals 3.\n"
"TRUNC(4.15,1) equals 4.1.\n"
"\n"
"@SEEALSO=INT")
};
static GnmValue *
gnumeric_trunc (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float number, p10;
int digits;
number = value_get_as_float (argv[0]);
if (argv[1] == NULL)
digits = 0;
else
digits = value_get_as_int (argv[1]);
p10 = gpow10 (digits);
return value_new_float (gnumeric_fake_trunc (number * p10) / p10);
}
/***************************************************************************/
static char const *help_even = {
N_("@FUNCTION=EVEN\n"
"@SYNTAX=EVEN(number)\n"
"@DESCRIPTION="
"EVEN function returns the number rounded up to the "
"nearest even integer. Negative numbers are rounded down.\n\n"
"* This function is Excel compatible.\n "
"\n"
"@EXAMPLES=\n"
"EVEN(5.4) equals 6.\n"
"EVEN(-5.4) equals -6.\n"
"\n"
"@SEEALSO=ODD")
};
static GnmValue *
gnumeric_even (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float number, ceiled;
int sign = 1;
number = value_get_as_float (argv[0]);
if (number < 0) {
sign = -1;
number = -number;
}
ceiled = ceilgnum (number);
if (fmodgnum (ceiled, 2) == 0)
if (number > ceiled)
return value_new_int ((int) (sign * (ceiled + 2)));
else
return value_new_int ((int) (sign * ceiled));
else
return value_new_int ((int) (sign * (ceiled + 1)));
}
/***************************************************************************/
static char const *help_odd = {
N_("@FUNCTION=ODD\n"
"@SYNTAX=ODD(number)\n"
"@DESCRIPTION="
"ODD function returns the @number rounded up to the "
"nearest odd integer. Negative numbers are rounded down.\n\n"
"* This function is Excel compatible.\n "
"\n"
"@EXAMPLES=\n"
"ODD(4.4) equals 5.\n"
"ODD(-4.4) equals -5.\n"
"\n"
"@SEEALSO=EVEN")
};
static GnmValue *
gnumeric_odd (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float number, ceiled;
int sign = 1;
number = value_get_as_float (argv[0]);
if (number < 0) {
sign = -1;
number = -number;
}
ceiled = ceilgnum (number);
if (fmodgnum (ceiled, 2) == 1)
if (number > ceiled)
return value_new_int ((int) (sign * (ceiled + 2)));
else
return value_new_int ((int) (sign * ceiled));
else
return value_new_int ((int) (sign * (ceiled + 1)));
}
/***************************************************************************/
static char const *help_factdouble = {
N_("@FUNCTION=FACTDOUBLE\n"
"@SYNTAX=FACTDOUBLE(number)\n"
"@DESCRIPTION="
"FACTDOUBLE function returns the double factorial "
"of a @number, i.e., x!!.\n"
"\n"
"* If @number is not an integer, it is truncated.\n"
"* If @number is negative FACTDOUBLE returns #NUM! error.\n"
"* This function is Excel compatible.\n "
"\n"
"@EXAMPLES=\n"
"FACTDOUBLE(5) equals 15.\n"
"\n"
"@SEEALSO=FACT")
};
static GnmValue *
gnumeric_factdouble (FunctionEvalInfo *ei, GnmValue **argv)
{
int number;
int n;
gnm_float product = 1;
number = value_get_as_int (argv[0]);
if (number < 0)
return value_new_error_NUM (ei->pos);
for (n = number; n > 0; n -= 2)
product *= n;
return value_new_float (product);
}
/***************************************************************************/
static char const *help_fib = {
N_("@FUNCTION=FIB\n"
"@SYNTAX=FIB(number)\n"
"@DESCRIPTION="
"FIB function computes Fibonacci numbers.\n"
"\n"
"* If @number is not an integer, it is truncated.\n"
"* If @number is negative or zero FIB returns #NUM! error.\n"
"\n"
"@EXAMPLES=\n"
"FIB(12) equals 144.\n"
"\n"
"@SEEALSO=")
};
static GnmValue *
gnumeric_fib (FunctionEvalInfo *ei, GnmValue **argv)
{
static int fibs[47];
static int fib_count = G_N_ELEMENTS (fibs);
static gboolean inited = FALSE;
int n = value_get_as_int (argv[0]);
if (n <= 0)
return value_new_error_NUM (ei->pos);
if (n < fib_count) {
if (!inited) {
int i;
fibs[1] = fibs[2] = 1;
for (i = 3; i < fib_count; i++)
fibs[i] = fibs[i - 1] + fibs[i - 2];
inited = TRUE;
}
return value_new_int (fibs[n]);
} else {
gnm_float s5 = sqrtgnum (5.0);
gnm_float r1 = (1 + s5) / 2;
gnm_float r2 = (1 - s5) / 2;
/* Use the Binet form. */
return value_new_float ((powgnum (r1, n) - powgnum (r2, n)) / s5);
}
}
/***************************************************************************/
static char const *help_quotient = {
N_("@FUNCTION=QUOTIENT\n"
"@SYNTAX=QUOTIENT(numerator,denominator)\n"
"@DESCRIPTION="
"QUOTIENT function returns the integer portion "
"of a division. @numerator is the divided number and "
"@denominator is the divisor.\n\n"
"* This function is Excel compatible.\n "
"\n"
"@EXAMPLES=\n"
"QUOTIENT(23,5) equals 4.\n"
"\n"
"@SEEALSO=MOD")
};
static GnmValue *
gnumeric_quotient (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float num, den;
num = value_get_as_float (argv[0]);
den = value_get_as_float (argv[1]);
if (den == 0)
return value_new_error_DIV0 (ei->pos);
else
return value_new_int ((int) (num / den));
}
/***************************************************************************/
static char const *help_sign = {
N_("@FUNCTION=SIGN\n"
"@SYNTAX=SIGN(number)\n"
"@DESCRIPTION="
"SIGN function returns 1 if the @number is positive, "
"zero if the @number is 0, and -1 if the @number is negative.\n\n"
"* This function is Excel compatible.\n "
"\n"
"@EXAMPLES=\n"
"SIGN(3) equals 1.\n"
"SIGN(-3) equals -1.\n"
"SIGN(0) equals 0.\n"
"\n"
"@SEEALSO=")
};
static GnmValue *
gnumeric_sign (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float n;
n = value_get_as_float (argv[0]);
if (n > 0)
return value_new_int (1);
else if (n == 0)
return value_new_int (0);
else
return value_new_int (-1);
}
/***************************************************************************/
static char const *help_sqrtpi = {
N_("@FUNCTION=SQRTPI\n"
"@SYNTAX=SQRTPI(number)\n"
"@DESCRIPTION="
"SQRTPI function returns the square root of a @number "
"multiplied by pi.\n\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"SQRTPI(2) equals 2.506628275.\n"
"\n"
"@SEEALSO=PI")
};
static GnmValue *
gnumeric_sqrtpi (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float n;
n = value_get_as_float (argv[0]);
if (n < 0)
return value_new_error_NUM (ei->pos);
return value_new_float (sqrtgnum (M_PIgnum * n));
}
/***************************************************************************/
static char const *help_rounddown = {
N_("@FUNCTION=ROUNDDOWN\n"
"@SYNTAX=ROUNDDOWN(number[,digits])\n"
"@DESCRIPTION="
"ROUNDDOWN function rounds a given @number down. "
"@number is the number you want rounded down and @digits is the "
"number of digits to which you want to round that number.\n"
"\n"
"* If @digits is greater than zero, @number is rounded down to the "
"given number of digits.\n"
"* If @digits is zero or omitted, @number is rounded down to the "
"nearest integer.\n"
"* If @digits is less than zero, @number is rounded down to the "
"left of the decimal point.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"ROUNDDOWN(5.5) equals 5.\n"
"ROUNDDOWN(-3.3) equals -4.\n"
"ROUNDDOWN(1501.15,1) equals 1501.1.\n"
"ROUNDDOWN(1501.15,-2) equals 1500.0.\n"
"\n"
"@SEEALSO=ROUND,ROUNDUP")
};
static GnmValue *
gnumeric_rounddown (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float number, p10;
int digits;
number = value_get_as_float (argv[0]);
if (argv[1] == NULL)
digits = 0;
else
digits = value_get_as_int (argv[1]);
p10 = gpow10 (digits);
return value_new_float (gnumeric_fake_floor (number * p10) / p10);
}
/***************************************************************************/
static char const *help_round = {
N_("@FUNCTION=ROUND\n"
"@SYNTAX=ROUND(number[,digits])\n"
"@DESCRIPTION="
"ROUND function rounds a given number.\n\n"
"@number is the number you want rounded and @digits is the "
"number of digits to which you want to round that number.\n"
"\n"
"* If @digits is greater than zero, @number is rounded to the "
"given number of digits.\n"
"* If @digits is zero or omitted, @number is rounded to the "
"nearest integer.\n"
"* If @digits is less than zero, @number is rounded to the left "
"of the decimal point.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"ROUND(5.5) equals 6.\n"
"ROUND(-3.3) equals -3.\n"
"ROUND(1501.15,1) equals 1501.2.\n"
"ROUND(1501.15,-2) equals 1500.0.\n"
"\n"
"@SEEALSO=ROUNDDOWN,ROUNDUP")
};
static GnmValue *
gnumeric_round (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float number, p10;
int digits;
number = value_get_as_float (argv[0]);
digits = argv[1] ? value_get_as_int (argv[1]) : 0;
p10 = gpow10 (digits);
return value_new_float (gnumeric_fake_round (number * p10) / p10);
}
/***************************************************************************/
static char const *help_roundup = {
N_("@FUNCTION=ROUNDUP\n"
"@SYNTAX=ROUNDUP(number[,digits])\n"
"@DESCRIPTION="
"ROUNDUP function rounds a given number up.\n\n"
"@number is the number you want rounded up and @digits is the "
"number of digits to which you want to round that number.\n"
"\n"
"* If @digits is greater than zero, @number is rounded up to the "
"given number of digits.\n"
"* If @digits is zero or omitted, @number is rounded up to the "
"nearest integer.\n"
"* If @digits is less than zero, @number is rounded up to the left "
"of the decimal point.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"ROUNDUP(5.5) equals 6.\n"
"ROUNDUP(-3.3) equals -3.\n"
"ROUNDUP(1501.15,1) equals 1501.2.\n"
"ROUNDUP(1501.15,-2) equals 1600.0.\n"
"\n"
"@SEEALSO=ROUND,ROUNDDOWN")
};
static GnmValue *
gnumeric_roundup (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float number, p10;
int digits;
number = value_get_as_float (argv[0]);
if (argv[1] == NULL)
digits = 0;
else
digits = value_get_as_int (argv[1]);
p10 = gpow10 (digits);
return value_new_float (gnumeric_fake_ceil (number * p10) / p10);
}
/***************************************************************************/
static char const *help_mround = {
N_("@FUNCTION=MROUND\n"
"@SYNTAX=MROUND(number,multiple)\n"
"@DESCRIPTION="
"MROUND function rounds a given number to the desired multiple.\n\n"
"@number is the number you want rounded and @multiple is the "
"the multiple to which you want to round the number.\n"
"\n"
"* If @number and @multiple have different sign, MROUND "
"returns #NUM! error.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"MROUND(1.7,0.2) equals 1.8.\n"
"MROUND(321.123,0.12) equals 321.12.\n"
"\n"
"@SEEALSO=ROUNDDOWN,ROUND,ROUNDUP")
};
static GnmValue *
gnumeric_mround (FunctionEvalInfo *ei, GnmValue **argv)
{
gnm_float const accuracy_limit = 0.0000003;
gnm_float number, multiple;
gnm_float div, mod;
int sign = 1;
number = value_get_as_float (argv[0]);
multiple = value_get_as_float (argv[1]);
/* Weird, but XL compatible. */
if (multiple == 0)
return value_new_int (0);
if ((number > 0 && multiple < 0)
|| (number < 0 && multiple > 0))
return value_new_error_NUM (ei->pos);
if (number < 0) {
sign = -1;
number = -number;
multiple = -multiple;
}
mod = fmodgnum (number, multiple);
div = number - mod;
return value_new_float (sign * (
div + ((mod + accuracy_limit >= multiple / 2) ? multiple : 0)));
}
/***************************************************************************/
static char const *help_roman = {
N_("@FUNCTION=ROMAN\n"
"@SYNTAX=ROMAN(number[,type])\n"
"@DESCRIPTION="
"ROMAN function returns an arabic number in the roman numeral "
"style, as text. @number is the number you want to convert and "
"@type is the type of roman numeral you want.\n"
"\n"
"* If @type is 0 or it is omitted, ROMAN returns classic roman "
"numbers.\n"
"* Type 1 is more concise than classic type, type 2 is more concise "
"than type 1, and type 3 is more concise than type 2. Type 4 "
"is simplified type."
"\n"
"* If @number is negative or greater than 3999, ROMAN returns "
"#VALUE! error.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"ROMAN(999) equals CMXCIX.\n"
"ROMAN(999,1) equals LMVLIV.\n"
"ROMAN(999,2) equals XMIX.\n"
"ROMAN(999,3) equals VMIV.\n"
"ROMAN(999,4) equals IM.\n"
"\n"
"@SEEALSO=")
};
static GnmValue *
gnumeric_roman (FunctionEvalInfo *ei, GnmValue **argv)
{
char const letter[] = { 'M', 'D', 'C', 'L', 'X', 'V', 'I' };
int const largest = 1000;
static char buf[256];
char *p;
int n, form;
int i, j, dec;
dec = largest;
n = value_get_as_int (argv[0]);
form = argv[1] ? value_get_as_int (argv[1]) : 0;
if (n < 0 || n > 3999)
return value_new_error_VALUE (ei->pos);
if (n == 0)
return value_new_string ("");
if (form < 0 || form > 4)
return value_new_error_NUM (ei->pos);
for (i = j = 0; dec > 1; dec /= 10, j += 2) {
for (; n > 0; i++) {
if (n >= dec) {
buf[i] = letter [j];
n -= dec;
} else if (n >= dec - dec / 10) {
buf [i++] = letter [j + 2];
buf [i] = letter [j];
n -= dec - dec / 10;
} else if (n >= dec / 2) {
buf [i] = letter [j + 1];
n -= dec / 2;
} else if (n >= dec / 2 - dec / 10) {
buf [i++] = letter [j + 2];
buf [i] = letter [j + 1];
n -= dec / 2 - dec / 10;
} else if (dec == 10) {
buf [i] = letter [j + 2];
n--;
} else
break;
}
}
buf [i] = '\0';
if (form > 0) {
/* Replace ``XLV'' with ``VL'' */
if ((p = strstr (buf, "XLV")) != NULL) {
*p++ = 'V';
*p++ = 'L';
for ( ; *p; p++)
*p = *(p+1);
}
/* Replace ``XCV'' with ``VC'' */
if ((p = strstr (buf, "XCV")) != NULL) {
*p++ = 'V';
*p++ = 'C';
for ( ; *p; p++)
*p = *(p+1);
}
/* Replace ``CDL'' with ``LD'' */
if ((p = strstr (buf, "CDL")) != NULL) {
*p++ = 'L';
*p++ = 'D';
for ( ; *p; p++)
*p = *(p+1);
}
/* Replace ``CML'' with ``LM'' */
if ((p = strstr (buf, "CML")) != NULL) {
*p++ = 'L';
*p++ = 'M';
for ( ; *p; p++)
*p = *(p+1);
}
/* Replace ``CMVC'' with ``LMVL'' */
if ((p = strstr (buf, "CMVC")) != NULL) {
*p++ = 'L';
*p++ = 'M';
*p++ = 'V';
*p++ = 'L';
}
}
if (form == 1) {
/* Replace ``CDXC'' with ``LDXL'' */
if ((p = strstr (buf, "CDXC")) != NULL) {
*p++ = 'L';
*p++ = 'D';
*p++ = 'X';
*p++ = 'L';
}
/* Replace ``CDVC'' with ``LDVL'' */
if ((p = strstr (buf, "CDVC")) != NULL) {
*p++ = 'L';
*p++ = 'D';
*p++ = 'V';
*p++ = 'L';
}
/* Replace ``CMXC'' with ``LMXL'' */
if ((p = strstr (buf, "CMXC")) != NULL) {
*p++ = 'L';
*p++ = 'M';
*p++ = 'X';
*p++ = 'L';
}
/* Replace ``XCIX'' with ``VCIV'' */
if ((p = strstr (buf, "XCIX")) != NULL) {
*p++ = 'V';
*p++ = 'C';
*p++ = 'I';
*p++ = 'V';
}
/* Replace ``XLIX'' with ``VLIV'' */
if ((p = strstr (buf, "XLIX")) != NULL) {
*p++ = 'V';
*p++ = 'L';
*p++ = 'I';
*p++ = 'V';
}
}
if (form > 1) {
/* Replace ``XLIX'' with ``IL'' */
if ((p = strstr (buf, "XLIX")) != NULL) {
*p++ = 'I';
*p++ = 'L';
for ( ; *p; p++)
*p = *(p+2);
}
/* Replace ``XCIX'' with ``IC'' */
if ((p = strstr (buf, "XCIX")) != NULL) {
*p++ = 'I';
*p++ = 'C';
for ( ; *p; p++)
*p = *(p+2);
}
/* Replace ``CDXC'' with ``XD'' */
if ((p = strstr (buf, "CDXC")) != NULL) {
*p++ = 'X';
*p++ = 'D';
for ( ; *p; p++)
*p = *(p+2);
}
/* Replace ``CDVC'' with ``XDV'' */
if ((p = strstr (buf, "CDVC")) != NULL) {
*p++ = 'X';
*p++ = 'D';
*p++ = 'V';
for ( ; *p; p++)
*p = *(p+1);
}
/* Replace ``CDIC'' with ``XDIX'' */
if ((p = strstr (buf, "CDIC")) != NULL) {
*p++ = 'X';
*p++ = 'D';
*p++ = 'I';
*p++ = 'X';
}
/* Replace ``LMVL'' with ``XMV'' */
if ((p = strstr (buf, "LMVL")) != NULL) {
*p++ = 'X';
*p++ = 'M';
*p++ = 'V';
for ( ; *p; p++)
*p = *(p+1);
}
/* Replace ``CMIC'' with ``XMIX'' */
if ((p = strstr (buf, "CMIC")) != NULL) {
*p++ = 'X';
*p++ = 'M';
*p++ = 'I';
*p++ = 'X';
}
/* Replace ``CMXC'' with ``XM'' */
if ((p = strstr (buf, "CMXC")) != NULL) {
*p++ = 'X';
*p++ = 'M';
for ( ; *p; p++)
*p = *(p+2);
}
}
if (form > 2) {
/* Replace ``XDV'' with ``VD'' */
if ((p = strstr (buf, "XDV")) != NULL) {
*p++ = 'V';
*p++ = 'D';
for ( ; *p; p++)
*p = *(p+1);
}
/* Replace ``XDIX'' with ``VDIV'' */
if ((p = strstr (buf, "XDIX")) != NULL) {
*p++ = 'V';
*p++ = 'D';
*p++ = 'I';
*p++ = 'V';
}
/* Replace ``XMV'' with ``VM'' */
if ((p = strstr (buf, "XMV")) != NULL) {
*p++ = 'V';
*p++ = 'M';
for ( ; *p; p++)
*p = *(p+1);
}
/* Replace ``XMIX'' with ``VMIV'' */
if ((p = strstr (buf, "XMIX")) != NULL) {
*p++ = 'V';
*p++ = 'M';
*p++ = 'I';
*p++ = 'V';
}
}
if (form == 4) {
/* Replace ``VDIV'' with ``ID'' */
if ((p = strstr (buf, "VDIV")) != NULL) {
*p++ = 'I';
*p++ = 'D';
for ( ; *p; p++)
*p = *(p+2);
}
/* Replace ``VMIV'' with ``IM'' */
if ((p = strstr (buf, "VMIV")) != NULL) {
*p++ = 'I';
*p++ = 'M';
for ( ; *p; p++)
*p = *(p+2);
}
}
return value_new_string (buf);
}
/***************************************************************************/
static char const *help_sumx2my2 = {
N_("@FUNCTION=SUMX2MY2\n"
"@SYNTAX=SUMX2MY2(array1,array2)\n"
"@DESCRIPTION="
"SUMX2MY2 function returns the sum of the difference of squares "
"of corresponding values in two arrays. @array1 is the first "
"array or range of data points and @array2 is the second array "
"or range of data points. The equation of SUMX2MY2 is "
"SUM (x^2-y^2).\n"
"\n"
"* Strings and empty cells are simply ignored.\n"
"* If @array1 and @array2 have different number of data points, "
"SUMX2MY2 returns #N/A error.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"Let us assume that the cells A1, A2, ..., A5 contain numbers "
"11, 15, 17, 21, and 43 and the cells B1, B2, ..., B5 hold "
"numbers 13, 22, 31, 33, and 39. Then\n"
"SUMX2MY2(A1:A5,B1:B5) equals -1299.\n"
"\n"
"@SEEALSO=SUMSQ,SUMX2PY2")
};
static GnmValue *
gnumeric_sumx2my2 (FunctionEvalInfo *ei, GnmValue **argv)
{
GnmValue *values_x = argv[0];
GnmValue *values_y = argv[1];
math_sums_t items_x, items_y;
GnmValue *ret;
gnm_float sum;
GSList *list1, *list2;
items_x.num = 0;
items_x.list = NULL;
items_y.num = 0;
items_y.list = NULL;
if (values_x->type == VALUE_CELLRANGE) {
ret = sheet_foreach_cell_in_range (
eval_sheet (ei->pos->sheet, ei->pos->sheet),
CELL_ITER_ALL,
values_x->v_range.cell.a.col,
values_x->v_range.cell.a.row,
values_x->v_range.cell.b.col,
values_x->v_range.cell.b.row,
callback_function_sumxy,
&items_x);
if (ret != NULL) {
ret = value_new_error_VALUE (ei->pos);
goto out;
}
} else {
ret = value_new_error (ei->pos,
_("Array version not implemented!"));
goto out;
}
if (values_y->type == VALUE_CELLRANGE) {
ret = sheet_foreach_cell_in_range (
eval_sheet (ei->pos->sheet, ei->pos->sheet),
CELL_ITER_ALL,
values_y->v_range.cell.a.col,
values_y->v_range.cell.a.row,
values_y->v_range.cell.b.col,
values_y->v_range.cell.b.row,
callback_function_sumxy,
&items_y);
if (ret != NULL) {
ret = value_new_error_VALUE (ei->pos);
goto out;
}
} else {
ret = value_new_error (ei->pos,
_("Array version not implemented!"));
goto out;
}
if (items_x.num != items_y.num) {
ret = value_new_error_NA (ei->pos);
goto out;
}
list1 = items_x.list;
list2 = items_y.list;
sum = 0;
while (list1 != NULL) {
gnm_float x, y;
x = *((gnm_float *) list1->data);
y = *((gnm_float *) list2->data);
sum += x * x - y * y;
list1 = list1->next;
list2 = list2->next;
}
ret = value_new_float (sum);
out:
for (list1 = items_x.list; list1; list1 = list1->next)
g_free (list1->data);
g_slist_free (items_x.list);
for (list2 = items_y.list; list2; list2 = list2->next)
g_free (list2->data);
g_slist_free (items_y.list);
return ret;
}
/***************************************************************************/
static char const *help_sumx2py2 = {
N_("@FUNCTION=SUMX2PY2\n"
"@SYNTAX=SUMX2PY2(array1,array2)\n"
"@DESCRIPTION="
"SUMX2PY2 function returns the sum of the sum of squares "
"of corresponding values in two arrays. @array1 is the first "
"array or range of data points and @array2 is the second array "
"or range of data points. The equation of SUMX2PY2 is "
"SUM (x^2+y^2).\n"
"\n"
"* Strings and empty cells are simply ignored.\n"
"* If @array1 and @array2 have different number of data points, "
"SUMX2PY2 returns #N/A error.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"Let us assume that the cells A1, A2, ..., A5 contain numbers "
"11, 15, 17, 21, and 43 and the cells B1, B2, ..., B5 hold "
"numbers 13, 22, 31, 33, and 39. Then\n"
"SUMX2PY2(A1:A5,B1:B5) equals 7149.\n"
"\n"
"@SEEALSO=SUMSQ,SUMX2MY2")
};
static GnmValue *
gnumeric_sumx2py2 (FunctionEvalInfo *ei, GnmValue **argv)
{
GnmValue *values_x = argv[0];
GnmValue *values_y = argv[1];
math_sums_t items_x, items_y;
GnmValue *ret;
gnm_float sum;
GSList *list1, *list2;
items_x.num = 0;
items_x.list = NULL;
items_y.num = 0;
items_y.list = NULL;
if (values_x->type == VALUE_CELLRANGE) {
ret = sheet_foreach_cell_in_range (
eval_sheet (ei->pos->sheet, ei->pos->sheet),
CELL_ITER_ALL, /* include empties so that the lists align */
values_x->v_range.cell.a.col,
values_x->v_range.cell.a.row,
values_x->v_range.cell.b.col,
values_x->v_range.cell.b.row,
callback_function_sumxy,
&items_x);
if (ret != NULL) {
ret = value_new_error_VALUE (ei->pos);
goto out;
}
} else {
ret = value_new_error (ei->pos,
_("Array version not implemented!"));
goto out;
}
if (values_y->type == VALUE_CELLRANGE) {
ret = sheet_foreach_cell_in_range (
eval_sheet (ei->pos->sheet, ei->pos->sheet),
CELL_ITER_ALL, /* include empties so that the lists align */
values_y->v_range.cell.a.col,
values_y->v_range.cell.a.row,
values_y->v_range.cell.b.col,
values_y->v_range.cell.b.row,
callback_function_sumxy,
&items_y);
if (ret != NULL) {
ret = value_new_error_VALUE (ei->pos);
goto out;
}
} else {
ret = value_new_error (ei->pos,
_("Array version not implemented!"));
goto out;
}
if (items_x.num != items_y.num) {
ret = value_new_error_NA (ei->pos);
goto out;
}
list1 = items_x.list;
list2 = items_y.list;
sum = 0;
while (list1 != NULL) {
gnm_float x, y;
x = *((gnm_float *) list1->data);
y = *((gnm_float *) list2->data);
sum += x * x + y * y;
list1 = list1->next;
list2 = list2->next;
}
ret = value_new_float (sum);
out:
for (list1 = items_x.list; list1; list1 = list1->next)
g_free (list1->data);
g_slist_free (items_x.list);
for (list2 = items_y.list; list2; list2 = list2->next)
g_free (list2->data);
g_slist_free (items_y.list);
return ret;
}
static char const *help_sumxmy2 = {
N_("@FUNCTION=SUMXMY2\n"
"@SYNTAX=SUMXMY2(array1,array2)\n"
"@DESCRIPTION="
"SUMXMY2 function returns the sum of squares of differences "
"of corresponding values in two arrays. @array1 is the first "
"array or range of data points and @array2 is the second array "
"or range of data points. The equation of SUMXMY2 is "
"SUM (x-y)^2.\n"
"\n"
"* Strings and empty cells are simply ignored.\n"
"* If @array1 and @array2 have different number of data points, "
"SUMXMY2 returns #N/A error.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"Let us assume that the cells A1, A2, ..., A5 contain numbers "
"11, 15, 17, 21, and 43 and the cells B1, B2, ..., B5 hold "
"numbers 13, 22, 31, 33, and 39. Then\n"
"SUMXMY2(A1:A5,B1:B5) equals 409.\n"
"\n"
"@SEEALSO=SUMSQ,SUMX2MY2,SUMX2PY2")
};
static GnmValue *
gnumeric_sumxmy2 (FunctionEvalInfo *ei, GnmValue **argv)
{
GnmValue *values_x = argv[0];
GnmValue *values_y = argv[1];
math_sums_t items_x, items_y;
GnmValue *ret;
gnm_float sum;
GSList *list1, *list2;
items_x.num = 0;
items_x.list = NULL;
items_y.num = 0;
items_y.list = NULL;
if (values_x->type == VALUE_CELLRANGE) {
ret = sheet_foreach_cell_in_range (
eval_sheet (ei->pos->sheet, ei->pos->sheet),
CELL_ITER_ALL, /* include empties so that the lists align */
values_x->v_range.cell.a.col,
values_x->v_range.cell.a.row,
values_x->v_range.cell.b.col,
values_x->v_range.cell.b.row,
callback_function_sumxy,
&items_x);
if (ret != NULL) {
ret = value_new_error_VALUE (ei->pos);
goto out;
}
} else {
ret = value_new_error (ei->pos,
_("Array version not implemented!"));
goto out;
}
if (values_y->type == VALUE_CELLRANGE) {
ret = sheet_foreach_cell_in_range (
eval_sheet (ei->pos->sheet, ei->pos->sheet),
CELL_ITER_ALL, /* include empties so that the lists align */
values_y->v_range.cell.a.col,
values_y->v_range.cell.a.row,
values_y->v_range.cell.b.col,
values_y->v_range.cell.b.row,
callback_function_sumxy,
&items_y);
if (ret != NULL) {
ret = value_new_error_VALUE (ei->pos);
goto out;
}
} else {
ret = value_new_error (ei->pos,
_("Array version not implemented!"));
goto out;
}
if (items_x.num != items_y.num) {
ret = value_new_error_NA (ei->pos);
goto out;
}
list1 = items_x.list;
list2 = items_y.list;
sum = 0;
while (list1 != NULL) {
gnm_float x, y;
x = *((gnm_float *) list1->data);
y = *((gnm_float *) list2->data);
sum += (x - y) * (x - y);
list1 = list1->next;
list2 = list2->next;
}
ret = value_new_float (sum);
out:
for (list1 = items_x.list; list1; list1 = list1->next)
g_free (list1->data);
g_slist_free (items_x.list);
for (list2 = items_y.list; list2; list2 = list2->next)
g_free (list2->data);
g_slist_free (items_y.list);
return ret;
}
/***************************************************************************/
static char const *help_seriessum = {
N_("@FUNCTION=SERIESSUM\n"
"@SYNTAX=SERIESSUM(x,n,m,coefficients)\n"
"@DESCRIPTION="
"SERIESSUM function returns the sum of a power series. @x is "
"the base of the power series, @n is the initial power to raise @x, "
"@m is the increment to the power for each term in the series, and "
"@coefficients are the coefficients by which each successive power "
"of @x is multiplied.\n\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"Let us assume that the cells A1, A2, ..., A5 contain numbers "
"1.23, 2.32, 2.98, 3.42, and 4.33. Then\n"
"SERIESSUM(3,1,2.23,A1:A5) equals 251416.43018.\n"
"\n"
"@SEEALSO=COUNT,SUM")
};
static int
range_seriessum (gnm_float const *xs, int n, gnm_float *res)
{
if (n >= 3) {
gnm_float x = xs[0];
gnm_float N = xs[1];
gnm_float m = xs[2];
gnm_float sum = 0;
gnm_float x_m = powgnum (x, m);
gnm_float xpow = powgnum (x, N);
int i;
for (i = 3; i < n; i++) {
sum += xs[i] * xpow;
xpow *= x_m;
}
*res = sum;
return 0;
} else
return 1;
}
static GnmValue *
gnumeric_seriessum (FunctionEvalInfo *ei, GnmExprList *nodes)
{
return float_range_function (nodes, ei,
range_seriessum,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_NUM);
}
/***************************************************************************/
static char const *help_minverse = {
N_("@FUNCTION=MINVERSE\n"
"@SYNTAX=MINVERSE(matrix)\n"
"@DESCRIPTION="
"MINVERSE function returns the inverse matrix of @matrix.\n"
"\n"
"* If @matrix cannot be inverted, MINVERSE returns #NUM! "
"error.\n"
"* If @matrix does not contain equal number of columns and "
"rows, MINVERSE returns #VALUE! error.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"\n"
"@SEEALSO=MMULT, MDETERM")
};
static GnmValue *
callback_function_mmult_validate (Sheet *sheet, int col, int row,
GnmCell *cell, void *user_data)
{
int *item_count = user_data;
cell_eval (cell);
if (!VALUE_IS_NUMBER (cell->value))
return VALUE_TERMINATE;
++(*item_count);
return NULL;
}
static gboolean
validate_range_numeric_matrix (GnmEvalPos const *ep, GnmValue * matrix,
int *rows, int *cols,
GnmStdError *err)
{
GnmValue *res;
int cell_count = 0;
*cols = value_area_get_width (matrix, ep);
*rows = value_area_get_height (matrix, ep);
/* No checking needed for arrays */
if (matrix->type == VALUE_ARRAY)
return FALSE;
if (matrix->v_range.cell.a.sheet != matrix->v_range.cell.b.sheet &&
matrix->v_range.cell.a.sheet != NULL &&
matrix->v_range.cell.b.sheet != NULL) {
*err = GNM_ERROR_VALUE;
return TRUE;
}
res = sheet_foreach_cell_in_range (
eval_sheet (matrix->v_range.cell.a.sheet, ep->sheet),
CELL_ITER_IGNORE_BLANK,
matrix->v_range.cell.a.col,
matrix->v_range.cell.a.row,
matrix->v_range.cell.b.col,
matrix->v_range.cell.b.row,
callback_function_mmult_validate,
&cell_count);
if (res != NULL || cell_count != (*rows * *cols)) {
/* As specified in the Excel Docs */
*err = GNM_ERROR_VALUE;
return TRUE;
}
return FALSE;
}
static gnm_float **
value_to_matrix (GnmValue const *v, int cols, int rows, GnmEvalPos const *ep)
{
gnm_float **res = g_new (gnm_float *, rows);
int r, c;
for (r = 0; r < rows; r++) {
res[r] = g_new (gnm_float, cols);
for (c = 0; c < cols; c++)
res[r][c] =
value_get_as_float (value_area_get_x_y (v, c, r, ep));
}
return res;
}
static void
free_matrix (gnm_float **mat, G_GNUC_UNUSED int cols, int rows)
{
int r;
for (r = 0; r < rows; r++)
g_free (mat[r]);
g_free (mat);
}
static GnmValue *
gnumeric_minverse (FunctionEvalInfo *ei, GnmValue **argv)
{
GnmEvalPos const * const ep = ei->pos;
int r, rows;
int c, cols;
GnmValue *res;
GnmValue *values = argv[0];
gnm_float **matrix;
GnmStdError err;
if (validate_range_numeric_matrix (ep, values, &rows, &cols, &err)) {
return value_new_error_std (ei->pos, err);
}
/* Guarantee shape and non-zero size */
if (cols != rows || !rows || !cols)
return value_new_error_VALUE (ei->pos);
matrix = value_to_matrix (values, cols, rows, ep);
if (!matrix_invert (matrix, rows)) {
free_matrix (matrix, cols, rows);
return value_new_error_NUM (ei->pos);
}
res = value_new_array_non_init (cols, rows);
for (c = 0; c < cols; ++c) {
res->v_array.vals[c] = g_new (GnmValue *, rows);
for (r = 0; r < rows; ++r) {
gnm_float tmp = matrix[r][c];
res->v_array.vals[c][r] = value_new_float (tmp);
}
}
free_matrix (matrix, cols, rows);
return res;
}
/***************************************************************************/
static char const *help_mmult = {
N_("@FUNCTION=MMULT\n"
"@SYNTAX=MMULT(array1,array2)\n"
"@DESCRIPTION="
"MMULT function returns the matrix product of two arrays. The "
"result is an array with the same number of rows as @array1 and "
"the same number of columns as @array2.\n\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"\n"
"@SEEALSO=TRANSPOSE,MINVERSE")
};
static GnmValue *
gnumeric_mmult (FunctionEvalInfo *ei, GnmValue **argv)
{
GnmEvalPos const * const ep = ei->pos;
int r, rows_a, rows_b;
int c, cols_a, cols_b;
GnmValue *res;
GnmValue *values_a = argv[0];
GnmValue *values_b = argv[1];
gnm_float *A, *B, *product;
GnmStdError err;
if (validate_range_numeric_matrix (ep, values_a, &rows_a, &cols_a,
&err) ||
validate_range_numeric_matrix (ep, values_b, &rows_b, &cols_b,
&err)) {
return value_new_error_std (ei->pos, err);
}
/* Guarantee shape and non-zero size */
if (cols_a != rows_b || !rows_a || !rows_b || !cols_a || !cols_b)
return value_new_error_VALUE (ei->pos);
res = value_new_array_non_init (cols_b, rows_a);
A = g_new (gnm_float, cols_a * rows_a);
B = g_new (gnm_float, cols_b * rows_b);
product = g_new (gnm_float, rows_a * cols_b);
for (c = 0; c < cols_a; c++)
for (r = 0; r < rows_a; r++) {
GnmValue const * a =
value_area_get_x_y (values_a, c, r, ep);
A[r + c * rows_a] = value_get_as_float (a);
}
for (c = 0; c < cols_b; c++)
for (r = 0; r < rows_b; r++) {
GnmValue const * b =
value_area_get_x_y (values_b, c, r, ep);
B[r + c * rows_b] = value_get_as_float (b);
}
mmult (A, B, cols_a, rows_a, cols_b, product);
for (c = 0; c < cols_b; c++) {
res->v_array.vals[c] = g_new (GnmValue *, rows_a);
for (r = 0; r < rows_a; r++)
res->v_array.vals[c][r] =
value_new_float (product [r + c * rows_a]);
}
g_free (A);
g_free (B);
g_free (product);
return res;
}
/***************************************************************************/
static char const *help_mdeterm = {
N_("@FUNCTION=MDETERM\n"
"@SYNTAX=MDETERM(matrix)\n"
"@DESCRIPTION="
"MDETERM function returns the determinant of a given matrix.\n"
"\n"
"* If the @matrix does not contain equal number of columns and "
"rows, MDETERM returns #VALUE! error.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"Let us assume that A1, ..., A4 contain numbers 2, 3, 7, and 3, "
"B1, ..., B4 4, 2, 4, and 1, C1, ..., C4 9, 4, 3, and 2, and "
"D1, ..., D4 7, 3, 6, and 5. Then\n"
"MDETERM(A1:D4) equals 148.\n"
"\n"
"@SEEALSO=MMULT, MINVERSE")
};
static GnmValue *
gnumeric_mdeterm (FunctionEvalInfo *ei, GnmValue **argv)
{
GnmEvalPos const * const ep = ei->pos;
int rows, cols;
gnm_float res;
GnmValue *values = argv[0];
gnm_float **matrix;
GnmStdError err;
if (validate_range_numeric_matrix (ep, values, &rows, &cols, &err))
return value_new_error_std (ei->pos, err);
/* Guarantee shape and non-zero size */
if (cols != rows || !rows || !cols)
return value_new_error_VALUE (ei->pos);
matrix = value_to_matrix (values, cols, rows, ep);
res = matrix_determinant (matrix, rows);
free_matrix (matrix, cols, rows);
return value_new_float (res);
}
/***************************************************************************/
static char const *help_sumproduct = {
N_("@FUNCTION=SUMPRODUCT\n"
"@SYNTAX=SUMPRODUCT(range1,range2,...)\n"
"@DESCRIPTION="
"SUMPRODUCT function multiplies corresponding data entries in the "
"given arrays or ranges, and then returns the sum of those "
"products. If an array entry is not numeric, the value zero is "
"used instead.\n"
"\n"
"* If arrays or range arguments do not have the same dimensions, "
"SUMPRODUCT returns #VALUE! error.\n"
"* This function is Excel compatible.\n"
"\n"
"@EXAMPLES=\n"
"Let us assume that the cells A1, A2, ..., A5 contain numbers "
"11, 15, 17, 21, and 43 and the cells B1, B2, ..., B5 hold "
"numbers 13, 22, 31, 33, and 39. Then\n"
"SUMPRODUCT(A1:A5,B1:B5) equals 3370.\n"
"\n"
"@SEEALSO=SUM,PRODUCT")
};
static GnmValue *
gnumeric_sumproduct (FunctionEvalInfo *ei, GnmExprList *args)
{
gnm_float **data;
GnmValue *result;
int i, argc;
GnmExprList *l;
gboolean size_error = FALSE;
int sizex = -1, sizey = -1;
if (args == NULL)
return value_new_error_VALUE (ei->pos);
argc = gnm_expr_list_length (args);
data = g_new0 (gnm_float *, argc);
for (l = args, i = 0; l; l = l->next, i++) {
int thissizex, thissizey, x, y;
GnmExpr const *expr = l->data;
GnmValue *val = gnm_expr_eval (expr, ei->pos,
GNM_EXPR_EVAL_PERMIT_NON_SCALAR |
GNM_EXPR_EVAL_PERMIT_EMPTY);
thissizex = value_area_get_width (val, ei->pos);
thissizey = value_area_get_height (val, ei->pos);
if (i == 0) {
sizex = thissizex;
sizey = thissizey;
} else if (sizex != thissizex || sizey != thissizey)
size_error = TRUE;
data[i] = g_new (gnm_float, thissizex * thissizey);
for (y = 0; y < thissizey; y++) {
for (x = 0; x < thissizex; x++) {
/* FIXME: efficiency worries? */
GnmValue const *v = value_area_fetch_x_y (val, x, y, ei->pos);
switch (v->type) {
case VALUE_ERROR :
/*
* We carefully tranverse the argument
* list and then the arrays in such an
* order that the first error we see is
* the final result.
*
* args: left-to-right.
* arrays: horizontal before vertical.
*
* Oh, size_error has the lowest
* significance -- it will be checked
* outside the arg loop.
*/
result = value_dup (v);
value_release (val);
goto done;
case VALUE_INTEGER:
case VALUE_FLOAT:
data[i][y * thissizex + x] = value_get_as_float (v);
break;
default :
/* Ignore booleans and strings to be consistent with XL */
data[i][y * thissizex + x] = 0.;
}
}
}
value_release (val);
}
if (size_error) {
/*
* If we found no errors in the data set and also the sizes
* do not match, we will get here.
*/
result = value_new_error_VALUE (ei->pos);
} else {
gnm_float sum = 0;
int j;
for (j = 0; j < sizex * sizey; j++) {
gnm_float product = data[0][j];
for (i = 1; i < argc; i++)
product *= data[i][j];
sum += product;
}
result = value_new_float (sum);
}
done:
for (i = 0; i < argc; i++)
g_free (data[i]);
g_free (data);
return result;
}
/***************************************************************************/
GnmFuncDescriptor const math_functions[] = {
{ "abs", "f", N_("number"), &help_abs,
gnumeric_abs, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
{ "acos", "f", N_("number"), &help_acos,
gnumeric_acos, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
{ "acosh", "f", N_("number"), &help_acosh,
gnumeric_acosh, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
{ "asin", "f", N_("number"), &help_asin,
gnumeric_asin, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
{ "asinh", "f", N_("number"), &help_asinh,
gnumeric_asinh, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
{ "atan", "f", N_("number"), &help_atan,
gnumeric_atan, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
{ "atanh", "f", N_("number"), &help_atanh,
gnumeric_atanh, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
{ "atan2", "ff", N_("xnum,ynum"), &help_atan2,
gnumeric_atan2, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
{ "cos", "f", N_("number"), &help_cos,
gnumeric_cos, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
{ "beta", "ff", N_("a,b"), &help_beta,
gnumeric_beta, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "betaln", "ff", N_("a,b"), &help_betaln,
gnumeric_betaln, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "cosh", "f", N_("number"), &help_cosh,
gnumeric_cosh, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
/* MS Excel puts this in statistical */
{ "countif", "rS", N_("range,criteria"), &help_countif,
gnumeric_countif, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "ceil", "f", N_("number"), &help_ceil,
gnumeric_ceil, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "ceiling", "ff", N_("number,significance"), &help_ceiling,
gnumeric_ceiling, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "degrees", "f", N_("number"), &help_degrees,
gnumeric_degrees, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
{ "even", "f", N_("number"), &help_even,
gnumeric_even, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "exp", "f", N_("number"), &help_exp,
gnumeric_exp, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "expm1", "f", N_("number"), &help_expm1,
gnumeric_expm1, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "fact", "f", N_("number"), &help_fact,
gnumeric_fact, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_SUPERSET, GNM_FUNC_TEST_STATUS_BASIC },
/* MS Excel puts this in the engineering functions */
{ "factdouble", "f", N_("number"), &help_factdouble,
gnumeric_factdouble, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "fib", "f", N_("number"), &help_fib,
gnumeric_fib, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "combin", "ff", N_("n,k"), &help_combin,
gnumeric_combin, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "floor", "f|f", N_("number"), &help_floor,
gnumeric_floor, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "gcd", NULL, N_("number,number"), &help_gcd,
NULL, gnumeric_gcd, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "hypot", NULL, "", &help_hypot,
NULL, gnumeric_hypot, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "int", "f", N_("number"), &help_int,
gnumeric_int, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "lcm", NULL, "", &help_lcm,
NULL, gnumeric_lcm, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "ln", "f", N_("number"), &help_ln,
gnumeric_ln, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "ln1p", "f", N_("number"), &help_ln1p,
gnumeric_ln1p, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "log", "f|f", N_("number,base"), &help_log,
gnumeric_log, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "log2", "f", N_("number"), &help_log2,
gnumeric_log2, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "log10", "f", N_("number"), &help_log10,
gnumeric_log10, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "mod", "ff", N_("numerator,denominator"), &help_mod,
gnumeric_mod, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "mround", "ff", N_("number,multiple"), &help_mround,
gnumeric_mround, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "multinomial", NULL, "", &help_multinomial,
NULL, gnumeric_multinomial, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "odd" , "f", N_("number"), &help_odd,
gnumeric_odd, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "power", "ff", N_("base,exponent"), &help_power,
gnumeric_power, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "g_product", NULL, N_("number"), &help_g_product,
NULL, gnumeric_g_product, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "quotient" , "ff", N_("numerator,denominator"), &help_quotient,
gnumeric_quotient, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "radians", "f", N_("number"), &help_radians,
gnumeric_radians, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
{ "roman", "f|f", N_("number,type"), &help_roman,
gnumeric_roman, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "round", "f|f", N_("number,digits"), &help_round,
gnumeric_round, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "rounddown", "f|f", N_("number,digits"), &help_rounddown,
gnumeric_rounddown, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "roundup", "f|f", N_("number,digits"), &help_roundup,
gnumeric_roundup, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "seriessum", NULL, N_("x,n,m,coefficients"), &help_seriessum,
NULL, gnumeric_seriessum, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "sign", "f", N_("number"), &help_sign,
gnumeric_sign, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "sin", "f", N_("number"), &help_sin,
gnumeric_sin, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
{ "sinh", "f", N_("number"), &help_sinh,
gnumeric_sinh, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
{ "sqrt", "f", N_("number"), &help_sqrt,
gnumeric_sqrt, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "sqrtpi", "f", N_("number"), &help_sqrtpi,
gnumeric_sqrtpi, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "suma", NULL, N_("number,number,"), &help_suma,
NULL, gnumeric_suma, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "sumif", "rS|r", N_("range,criteria,actual_range"), &help_sumif,
gnumeric_sumif, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "sumproduct", NULL, N_("range,range,"), &help_sumproduct,
NULL, gnumeric_sumproduct, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "sumsq", NULL, N_("number"), &help_sumsq,
NULL, gnumeric_sumsq, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "sumx2my2", "AA", N_("array1,array2"), &help_sumx2my2,
gnumeric_sumx2my2, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "sumx2py2", "AA", N_("array1,array2"), &help_sumx2py2,
gnumeric_sumx2py2, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "sumxmy2", "AA", N_("array1,array2"), &help_sumxmy2,
gnumeric_sumxmy2, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "tan", "f", N_("number"), &help_tan,
gnumeric_tan, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
{ "tanh", "f", N_("number"), &help_tanh,
gnumeric_tanh, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
{ "trunc", "f|f", N_("number,digits"), &help_trunc,
gnumeric_trunc, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "pi", "", "", &help_pi,
gnumeric_pi, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_EXHAUSTIVE },
{ "mmult", "AA", N_("array1,array2"), &help_mmult,
gnumeric_mmult, NULL, NULL, NULL, NULL,
GNM_FUNC_RETURNS_NON_SCALAR, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "minverse","A", N_("array"), &help_minverse,
gnumeric_minverse, NULL, NULL, NULL, NULL,
GNM_FUNC_RETURNS_NON_SCALAR, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "mdeterm", "A", N_("array,matrix_type,bandsize"), &help_mdeterm,
gnumeric_mdeterm, NULL, NULL, NULL, NULL,
GNM_FUNC_RETURNS_NON_SCALAR, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
#if 0
{ "logmdeterm", "A|si", N_("array,matrix_type,bandsize"),
&help_logmdeterm, gnumeric_logmdeterm, NULL, NULL, NULL },
#endif
{NULL}
};
|