Mercurial > vim
annotate src/float.c @ 32936:c517845bd10e v9.0.1776
patch 9.0.1776: No support for stable Python 3 ABI
Commit: https://github.com/vim/vim/commit/c13b3d1350b60b94fe87f0761ea31c0e7fb6ebf3
Author: Yee Cheng Chin <ychin.git@gmail.com>
Date: Sun Aug 20 21:18:38 2023 +0200
patch 9.0.1776: No support for stable Python 3 ABI
Problem: No support for stable Python 3 ABI
Solution: Support Python 3 stable ABI
Commits:
1) Support Python 3 stable ABI to allow mixed version interoperatbility
Vim currently supports embedding Python for use with plugins, and the
"dynamic" linking option allows the user to specify a locally installed
version of Python by setting `pythonthreedll`. However, one caveat is
that the Python 3 libs are not binary compatible across minor versions,
and mixing versions can potentially be dangerous (e.g. let's say Vim was
linked against the Python 3.10 SDK, but the user sets `pythonthreedll`
to a 3.11 lib). Usually, nothing bad happens, but in theory this could
lead to crashes, memory corruption, and other unpredictable behaviors.
It's also difficult for the user to tell something is wrong because Vim
has no way of reporting what Python 3 version Vim was linked with.
For Vim installed via a package manager, this usually isn't an issue
because all the dependencies would already be figured out. For prebuilt
Vim binaries like MacVim (my motivation for working on this), AppImage,
and Win32 installer this could potentially be an issue as usually a
single binary is distributed. This is more tricky when a new Python
version is released, as there's a chicken-and-egg issue with deciding
what Python version to build against and hard to keep in sync when a new
Python version just drops and we have a mix of users of different Python
versions, and a user just blindly upgrading to a new Python could lead to
bad interactions with Vim.
Python 3 does have a solution for this problem: stable ABI / limited API
(see https://docs.python.org/3/c-api/stable.html). The C SDK limits the
API to a set of functions that are promised to be stable across
versions. This pull request adds an ifdef config that allows us to turn
it on when building Vim. Vim binaries built with this option should be
safe to freely link with any Python 3 libraies without having the
constraint of having to use the same minor version.
Note: Python 2 has no such concept and this doesn't change how Python 2
integration works (not that there is going to be a new version of Python
2 that would cause compatibility issues in the future anyway).
---
Technical details:
======
The stable ABI can be accessed when we compile with the Python 3 limited
API (by defining `Py_LIMITED_API`). The Python 3 code (in `if_python3.c`
and `if_py_both.h`) would now handle this and switch to limited API
mode. Without it set, Vim will still use the full API as before so this
is an opt-in change.
The main difference is that `PyType_Object` is now an opaque struct that
we can't directly create "static types" out of, and we have to create
type objects as "heap types" instead. This is because the struct is not
stable and changes from version to version (e.g. 3.8 added a
`tp_vectorcall` field to it). I had to change all the types to be
allocated on the heap instead with just a pointer to them.
Other functions are also simply missing in limited API, or they are
introduced too late (e.g. `PyUnicode_AsUTF8AndSize` in 3.10) to it that
we need some other ways to do the same thing, so I had to abstract a few
things into macros, and sometimes re-implement functions like
`PyObject_NEW`.
One caveat is that in limited API, `OutputType` (used for replacing
`sys.stdout`) no longer inherits from `PyStdPrinter_Type` which I don't
think has any real issue other than minor differences in how they
convert to a string and missing a couple functions like `mode()` and
`fileno()`.
Also fixed an existing bug where `tp_basicsize` was set incorrectly for
`BufferObject`, `TabListObject, `WinListObject`.
Technically, there could be a small performance drop, there is a little
more indirection with accessing type objects, and some APIs like
`PyUnicode_AsUTF8AndSize` are missing, but in practice I didn't see any
difference, and any well-written Python plugin should try to avoid
excessing callbacks to the `vim` module in Python anyway.
I only tested limited API mode down to Python 3.7, which seemes to
compile and work fine. I haven't tried earlier Python versions.
2) Fix PyIter_Check on older Python vers / type##Ptr unused warning
For PyIter_Check, older versions exposed them as either macros (used in
full API), or a function (for use in limited API). A previous change
exposed PyIter_Check to the dynamic build because Python just moved it
to function-only in 3.10 anyway. Because of that, just make sure we
always grab the function in dynamic builds in earlier versions since
that's what Python eventually did anyway.
3) Move Py_LIMITED_API define to configure script
Can now use --with-python-stable-abi flag to customize what stable ABI
version to target. Can also use an env var to do so as well.
4) Show +python/dyn-stable in :version, and allow has() feature query
Not sure if the "/dyn-stable" suffix would break things, or whether we
should do it another way. Or just don't show it in version and rely on
has() feature checking.
5) Documentation first draft. Still need to implement v:python3_version
6) Fix PyIter_Check build breaks when compiling against Python 3.8
7) Add CI coverage stable ABI on Linux/Windows / make configurable on Windows
This adds configurable options for Windows make files (both MinGW and
MSVC). CI will also now exercise both traditional full API and stable
ABI for Linux and Windows in the matrix for coverage.
Also added a "dynamic" option to Linux matrix as a drive-by change to
make other scripting languages like Ruby / Perl testable under both
static and dynamic builds.
8) Fix inaccuracy in Windows docs
Python's own docs are confusing but you don't actually want to use
`python3.dll` for the dynamic linkage.
9) Add generated autoconf file
10) Add v:python3_version support
This variable indicates the version of Python3 that Vim was built
against (PY_VERSION_HEX), and will be useful to check whether the Python
library you are loading in dynamically actually fits it. When built with
stable ABI, it will be the limited ABI version instead
(`Py_LIMITED_API`), which indicates the minimum version of Python 3 the
user should have, rather than the exact match. When stable ABI is used,
we won't be exposing PY_VERSION_HEX in this var because it just doesn't
seem necessary to do so (the whole point of stable ABI is the promise
that it will work across versions), and I don't want to confuse the user
with too many variables.
Also, cleaned up some documentation, and added help tags.
11) Fix Python 3.7 compat issues
Fix a couple issues when using limited API < 3.8
- Crash on exit: In Python 3.7, if a heap-allocated type is destroyed
before all instances are, it would cause a crash later. This happens
when we destroyed `OptionsType` before calling `Py_Finalize` when
using the limited API. To make it worse, later versions changed the
semantics and now each instance has a strong reference to its own type
and the recommendation has changed to have each instance de-ref its
own type and have its type in GC traversal. To avoid dealing with
these cross-version variations, we just don't free the heap type. They
are static types in non-limited-API anyway and are designed to last
through the entirety of the app, and we also don't restart the Python
runtime and therefore do not need it to have absolutely 0 leaks.
See:
- https://docs.python.org/3/whatsnew/3.8.html#changes-in-the-c-api
- https://docs.python.org/3/whatsnew/3.9.html#changes-in-the-c-api
- PyIter_Check: This function is not provided in limited APIs older than
3.8. Previously I was trying to mock it out using manual
PyType_GetSlot() but it was brittle and also does not actually work
properly for static types (it will generate a Python error). Just
return false. It does mean using limited API < 3.8 is not recommended
as you lose the functionality to handle iterators, but from playing
with plugins I couldn't find it to be an issue.
- Fix loading of PyIter_Check so it will be done when limited API < 3.8.
Otherwise loading a 3.7 Python lib will fail even if limited API was
specified to use it.
12) Make sure to only load `PyUnicode_AsUTF8AndSize` in needed in limited API
We don't use this function unless limited API >= 3.10, but we were
loading it regardless. Usually it's ok in Unix-like systems where Python
just has a single lib that we load from, but in Windows where there is a
separate python3.dll this would not work as the symbol would not have
been exposed in this more limited DLL file. This makes it much clearer
under what condition is this function needed.
closes: #12032
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 20 Aug 2023 21:30:04 +0200 |
parents | f1d5ad2b978e |
children |
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 |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
291 if (get_float_arg(argvars, &f) != OK) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
292 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
293 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
294 if (f <= (float_T)-VARNUM_MAX + DBL_EPSILON) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
295 rettv->vval.v_number = -VARNUM_MAX; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
296 else if (f >= (float_T)VARNUM_MAX - DBL_EPSILON) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
297 rettv->vval.v_number = VARNUM_MAX; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
298 else |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
299 rettv->vval.v_number = (varnumber_T)f; |
24780
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 |