annotate src/float.c @ 31555:5aa54cbc6e20 v9.0.1110

patch 9.0.1110: build fails on Mac OS X 10.4/10.5 Commit: https://github.com/vim/vim/commit/254480736f7db3667c7b84873efb49c2cb1d385f Author: Evan Miller <emmiller@gmail.com> Date: Fri Dec 30 10:42:23 2022 +0000 patch 9.0.1110: build fails on Mac OS X 10.4/10.5 Problem: Build fails on Mac OS X 10.4/10.5 . Solution: Check if the dispatch/dispatch.h header exists. (Evan Miller, closes #11746)
author Bram Moolenaar <Bram@vim.org>
date Fri, 30 Dec 2022 11:45:05 +0100
parents 029c59bf78f1
children f1d5ad2b978e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * float.c: Floating point functions
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 #define USING_FLOAT_STUFF
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 #include "vim.h"
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 30053
diff changeset
17 #if defined(FEAT_EVAL) || defined(PROTO)
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 #ifdef VMS
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 # include <float.h>
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 #endif
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 * Convert the string "text" to a floating point number.
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 * This uses strtod(). setlocale(LC_NUMERIC, "C") has been used to make sure
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 * this always uses a decimal point.
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 * Returns the length of the text that was consumed.
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 int
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 string2float(
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 char_u *text,
25557
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
32 float_T *value, // result stored here
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
33 int skip_quotes)
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 char *s = (char *)text;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 float_T f;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 // MS-Windows does not deal with "inf" and "nan" properly.
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 if (STRNICMP(text, "inf", 3) == 0)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 *value = INFINITY;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 return 3;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 if (STRNICMP(text, "-inf", 3) == 0)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 *value = -INFINITY;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 return 4;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 if (STRNICMP(text, "nan", 3) == 0)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 *value = NAN;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 return 3;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 }
25557
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
54 if (skip_quotes && vim_strchr((char_u *)s, '\'') != NULL)
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
55 {
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
56 char_u buf[100];
30053
f5cbf8a4043d patch 9.0.0364: clang static analyzer gives warnings
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
57 char_u *p;
25557
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
58 int quotes = 0;
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
59
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
60 vim_strncpy(buf, (char_u *)s, 99);
30053
f5cbf8a4043d patch 9.0.0364: clang static analyzer gives warnings
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
61 for (p = buf; ; p = skipdigits(p))
25557
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
62 {
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
63 // remove single quotes between digits, not in the exponent
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
64 if (*p == '\'')
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
65 {
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
66 ++quotes;
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
67 mch_memmove(p, p + 1, STRLEN(p));
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
68 }
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
69 if (!vim_isdigit(*p))
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
70 break;
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
71 }
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
72 s = (char *)buf;
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
73 f = strtod(s, &s);
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
74 *value = f;
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
75 return (int)((char_u *)s - buf) + quotes;
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
76 }
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
77
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 f = strtod(s, &s);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 *value = f;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 return (int)((char_u *)s - text);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 * Get the float value of "argvars[0]" into "f".
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 * Returns FAIL when the argument is not a Number or Float.
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 static int
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 get_float_arg(typval_T *argvars, float_T *f)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 if (argvars[0].v_type == VAR_FLOAT)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 *f = argvars[0].vval.v_float;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 return OK;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 if (argvars[0].v_type == VAR_NUMBER)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 *f = (float_T)argvars[0].vval.v_number;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 return OK;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 }
26962
85866e069c24 patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 25557
diff changeset
100 emsg(_(e_number_or_float_required));
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 return FAIL;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 * "abs(expr)" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 f_abs(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 {
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
110 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
111 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
112
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 if (argvars[0].v_type == VAR_FLOAT)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 rettv->vval.v_float = fabs(argvars[0].vval.v_float);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 varnumber_T n;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 int error = FALSE;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 n = tv_get_number_chk(&argvars[0], &error);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 if (error)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 rettv->vval.v_number = -1;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 else if (n > 0)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 rettv->vval.v_number = n;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 rettv->vval.v_number = -n;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 * "acos()" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 f_acos(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 float_T f = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
141 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
142 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
143
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 if (get_float_arg(argvars, &f) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 rettv->vval.v_float = acos(f);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 rettv->vval.v_float = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 * "asin()" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 f_asin(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 float_T f = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
159 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
160 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
161
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 if (get_float_arg(argvars, &f) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 rettv->vval.v_float = asin(f);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 rettv->vval.v_float = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 * "atan()" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 f_atan(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 float_T f = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
177 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
178 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
179
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 if (get_float_arg(argvars, &f) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 rettv->vval.v_float = atan(f);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 rettv->vval.v_float = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 * "atan2()" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 f_atan2(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 float_T fx = 0.0, fy = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
195 if (in_vim9script()
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
196 && (check_for_float_or_nr_arg(argvars, 0) == FAIL
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
197 || check_for_float_or_nr_arg(argvars, 1) == FAIL))
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
198 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
199
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 if (get_float_arg(argvars, &fx) == OK
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 && get_float_arg(&argvars[1], &fy) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 rettv->vval.v_float = atan2(fx, fy);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 rettv->vval.v_float = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 * "ceil({float})" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 f_ceil(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 float_T f = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
216 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
217 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
218
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 if (get_float_arg(argvars, &f) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 rettv->vval.v_float = ceil(f);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 rettv->vval.v_float = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 * "cos()" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 f_cos(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 float_T f = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
234 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
235 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
236
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 if (get_float_arg(argvars, &f) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 rettv->vval.v_float = cos(f);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 rettv->vval.v_float = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 * "cosh()" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 f_cosh(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 float_T f = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
252 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
253 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
254
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 if (get_float_arg(argvars, &f) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 rettv->vval.v_float = cosh(f);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 rettv->vval.v_float = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 * "exp()" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 f_exp(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 float_T f = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
270 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
271 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
272
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 if (get_float_arg(argvars, &f) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 rettv->vval.v_float = exp(f);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 rettv->vval.v_float = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 * "float2nr({float})" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 f_float2nr(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 float_T f = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
288 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
289 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
290
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 if (get_float_arg(argvars, &f) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 if (f <= (float_T)-VARNUM_MAX + DBL_EPSILON)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 rettv->vval.v_number = -VARNUM_MAX;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 else if (f >= (float_T)VARNUM_MAX - DBL_EPSILON)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 rettv->vval.v_number = VARNUM_MAX;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 rettv->vval.v_number = (varnumber_T)f;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 * "floor({float})" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 f_floor(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 float_T f = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
310 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
311 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
312
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 if (get_float_arg(argvars, &f) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 rettv->vval.v_float = floor(f);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 rettv->vval.v_float = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 * "fmod()" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 f_fmod(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 float_T fx = 0.0, fy = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
328 if (in_vim9script()
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
329 && (check_for_float_or_nr_arg(argvars, 0) == FAIL
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
330 || check_for_float_or_nr_arg(argvars, 1) == FAIL))
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
331 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
332
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 if (get_float_arg(argvars, &fx) == OK
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 && get_float_arg(&argvars[1], &fy) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 rettv->vval.v_float = fmod(fx, fy);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 rettv->vval.v_float = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 # if defined(HAVE_MATH_H) || defined(PROTO)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 * "isinf()" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 f_isinf(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 {
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
348 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
349 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
350
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 if (argvars[0].v_type == VAR_FLOAT && isinf(argvars[0].vval.v_float))
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 rettv->vval.v_number = argvars[0].vval.v_float > 0.0 ? 1 : -1;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 * "isnan()" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 f_isnan(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 {
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
361 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
362 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
363
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 rettv->vval.v_number = argvars[0].v_type == VAR_FLOAT
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 && isnan(argvars[0].vval.v_float);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 # endif
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 * "log()" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 f_log(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 float_T f = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
377 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
378 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
379
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 if (get_float_arg(argvars, &f) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 rettv->vval.v_float = log(f);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 rettv->vval.v_float = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 * "log10()" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 f_log10(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 float_T f = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
395 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
396 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
397
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 if (get_float_arg(argvars, &f) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 rettv->vval.v_float = log10(f);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 rettv->vval.v_float = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 * "pow()" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 f_pow(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 float_T fx = 0.0, fy = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
413 if (in_vim9script()
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
414 && (check_for_float_or_nr_arg(argvars, 0) == FAIL
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
415 || check_for_float_or_nr_arg(argvars, 1) == FAIL))
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
416 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
417
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 if (get_float_arg(argvars, &fx) == OK
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 && get_float_arg(&argvars[1], &fy) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 rettv->vval.v_float = pow(fx, fy);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 rettv->vval.v_float = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 * round() is not in C90, use ceil() or floor() instead.
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 float_T
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 vim_round(float_T f)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 return f > 0 ? floor(f + 0.5) : ceil(f - 0.5);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 * "round({float})" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 f_round(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 float_T f = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
444 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
445 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
446
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 if (get_float_arg(argvars, &f) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 rettv->vval.v_float = vim_round(f);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 rettv->vval.v_float = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 * "sin()" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 f_sin(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 float_T f = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
462 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
463 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
464
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 if (get_float_arg(argvars, &f) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 rettv->vval.v_float = sin(f);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 rettv->vval.v_float = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 * "sinh()" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 f_sinh(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 float_T f = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
480 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
481 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
482
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 if (get_float_arg(argvars, &f) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 rettv->vval.v_float = sinh(f);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 rettv->vval.v_float = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 * "sqrt()" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 f_sqrt(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 float_T f = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
498 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
499 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
500
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 if (get_float_arg(argvars, &f) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 rettv->vval.v_float = sqrt(f);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 rettv->vval.v_float = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 * "str2float()" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 f_str2float(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 {
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
514 char_u *p;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
515 int isneg;
25557
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
516 int skip_quotes;
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
517
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
518 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
519 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
520
25557
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
521 skip_quotes = argvars[1].v_type != VAR_UNKNOWN && tv_get_bool(&argvars[1]);
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
522
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
523 p = skipwhite(tv_get_string_strict(&argvars[0]));
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
524 isneg = (*p == '-');
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 if (*p == '+' || *p == '-')
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 p = skipwhite(p + 1);
25557
763ea8f075db patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
528 (void)string2float(p, &rettv->vval.v_float, skip_quotes);
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 if (isneg)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 rettv->vval.v_float *= -1;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 * "tan()" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 f_tan(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 float_T f = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
542 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
543 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
544
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 if (get_float_arg(argvars, &f) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 rettv->vval.v_float = tan(f);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 rettv->vval.v_float = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 * "tanh()" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 f_tanh(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 float_T f = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
560 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
561 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
562
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 if (get_float_arg(argvars, &f) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 rettv->vval.v_float = tanh(f);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 rettv->vval.v_float = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 /*
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 * "trunc({float})" function
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 */
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 void
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 f_trunc(typval_T *argvars, typval_T *rettv)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 {
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 float_T f = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
578 if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
579 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
580
24780
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 rettv->v_type = VAR_FLOAT;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 if (get_float_arg(argvars, &f) == OK)
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 // trunc() is not in C90, use floor() or ceil() instead.
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 rettv->vval.v_float = f > 0 ? floor(f) : ceil(f);
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 else
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 rettv->vval.v_float = 0.0;
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 }
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588
7bc92a651472 patch 8.2.2928: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 #endif