[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Add arithmetic builtin functions
From: |
Gisle Vanem |
Subject: |
Re: [PATCH] Add arithmetic builtin functions |
Date: |
Fri, 29 Nov 2024 16:34:04 +0100 |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 |
Pete Dietl wrote:
Here I submit to you a patch that adds the following builtin functions
to make: `add` (addition), `sub` (subtraction), `mul`
(multiplication), `div` (division), `mod` (modulus), `max` (maximum),
`min` (minimum), and `abs` (absolute value). The implementation I
provide supports both integers and floats with promotions from integer
to float when appropriate (an operation where at least one argument is
a float causes the other argument to be promoted to a float and the
result to be a float).
This would be nice, but...
+#define generic_math_op(a, b, op) \
+ ((void)sizeof ( \
+ char[__builtin_types_compatible_p (typeof (a), typeof (b)) ? 1 : -1]), \
+ _Generic ((a), \
+ double: generic_math_op_double, \
+ long long int: generic_math_op_ll) (a, b, op))
this is some GNU-C-ism that wont compile with MSVC.
+static char *
+func_add (char *o, char **argv, const char *funcname)
+{
+ struct number n = perform_math_op (
+ op_add, funcname,
+ (struct math_operation_init){ .init_type = t_constant, .constant = 0 },
+ argv);
Not sure about such inline 'structs'.
--
--gv