Path: blob/main/core/posix-wasm/src/lib/builtins/multc3.c
1067 views
//===-- multc3.c - Implement __multc3 -------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file implements __multc3 for the compiler_rt library.9//10//===----------------------------------------------------------------------===//1112#include "int_lib.h"13#include "int_math.h"1415// Returns: the product of a + ib and c + id1617COMPILER_RT_ABI long double _Complex __multc3(long double a, long double b,18long double c, long double d) {19long double ac = a * c;20long double bd = b * d;21long double ad = a * d;22long double bc = b * c;23long double _Complex z;24__real__ z = ac - bd;25__imag__ z = ad + bc;26if (crt_isnan(__real__ z) && crt_isnan(__imag__ z)) {27int recalc = 0;28if (crt_isinf(a) || crt_isinf(b)) {29a = crt_copysignl(crt_isinf(a) ? 1 : 0, a);30b = crt_copysignl(crt_isinf(b) ? 1 : 0, b);31if (crt_isnan(c))32c = crt_copysignl(0, c);33if (crt_isnan(d))34d = crt_copysignl(0, d);35recalc = 1;36}37if (crt_isinf(c) || crt_isinf(d)) {38c = crt_copysignl(crt_isinf(c) ? 1 : 0, c);39d = crt_copysignl(crt_isinf(d) ? 1 : 0, d);40if (crt_isnan(a))41a = crt_copysignl(0, a);42if (crt_isnan(b))43b = crt_copysignl(0, b);44recalc = 1;45}46if (!recalc &&47(crt_isinf(ac) || crt_isinf(bd) || crt_isinf(ad) || crt_isinf(bc))) {48if (crt_isnan(a))49a = crt_copysignl(0, a);50if (crt_isnan(b))51b = crt_copysignl(0, b);52if (crt_isnan(c))53c = crt_copysignl(0, c);54if (crt_isnan(d))55d = crt_copysignl(0, d);56recalc = 1;57}58if (recalc) {59__real__ z = CRT_INFINITY * (a * c - b * d);60__imag__ z = CRT_INFINITY * (a * d + b * c);61}62}63return z;64}656667