ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
fp_tan.c
Go to the documentation of this file.
1/*****************************************************************************
2 * ugBASIC - an isomorphic BASIC language compiler for retrocomputers *
3 *****************************************************************************
4 * Copyright 2021-2026 Marco Spedaletti (asimov@mclink.it)
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *----------------------------------------------------------------------------
18 * Concesso in licenza secondo i termini della Licenza Apache, versione 2.0
19 * (la "Licenza"); è proibito usare questo file se non in conformità alla
20 * Licenza. Una copia della Licenza è disponibile all'indirizzo:
21 *
22 * http://www.apache.org/licenses/LICENSE-2.0
23 *
24 * Se non richiesto dalla legislazione vigente o concordato per iscritto,
25 * il software distribuito nei termini della Licenza è distribuito
26 * "COSÌ COM'È", SENZA GARANZIE O CONDIZIONI DI ALCUN TIPO, esplicite o
27 * implicite. Consultare la Licenza per il testo specifico che regola le
28 * autorizzazioni e le limitazioni previste dalla medesima.
29 ****************************************************************************/
30
31/****************************************************************************
32 * INCLUDE SECTION
33 ****************************************************************************/
34
35#include "../../ugbc.h"
36#include <math.h>
37
38/****************************************************************************
39 * CODE SECTION
40 ****************************************************************************/
41
42/* <usermanual>
43@keyword TAN (function)
44
45@english
46This function will calculate the tangent value of an angle. It is the ratio
47of the opposite side and the adjacent side of the angle in consideration in
48a right-angled triangle.
49
50@italian
51Questa funzione calcolerà il valore della tangente di un angolo. È il rapporto
52tra il lato opposto e il lato adiacente dell'angolo considerato in un triangolo
53rettangolo.
54
55@syntax = TAN(angle)
56
57@example x = TAN(0)
58
59@usedInExample float_tan.bas
60
61</usermanual> */
62Variable * fp_tan( Environment * _environment, char * _angle ) {
63
64 Variable * angle = variable_retrieve_or_define( _environment, _angle, VT_FLOAT, 0 );
65 Variable * result = variable_temporary( _environment, VT_FLOAT, "(tan)");
66
67 switch( result->precision ) {
68 case FT_FAST:
69 if ( _environment->floatType.angle == FT_DEGREE ) {
70 Variable * pi = variable_temporary( _environment, VT_FLOAT, "(float)" );
71#if defined(__c128z__) || defined(__vg5000__) || defined(__zx__) || \
72 defined(__coleco__) || defined(__cpc__) || defined(__sc3000__) || \
73 defined(__sc3000__) || defined(__sg1000__) || defined(__msx1__) || \
74 defined(__gb__)
75 variable_store_float( _environment, pi->name, M_PI );
76#else
77 cpu_move_32bit( _environment, "PI", pi->realName );
78#endif
79 Variable * d180 = variable_temporary( _environment, VT_FLOAT, "(d180)" );
80 variable_store_float( _environment, d180->name, 180.0 );
81 Variable * radianAngle = variable_temporary( _environment, VT_FLOAT, "(tan)");
82 cpu_float_fast_mul( _environment, angle->realName, pi->realName, radianAngle->realName );
83 cpu_float_fast_div( _environment, radianAngle->realName, d180->realName, radianAngle->realName );
84 cpu_float_fast_tan( _environment, radianAngle->realName, result->realName );
85 } else {
86 cpu_float_fast_tan( _environment, angle->realName, result->realName );
87 }
88 break;
89 case FT_SINGLE:
90 if ( _environment->floatType.angle == FT_DEGREE ) {
91 Variable * pi = variable_temporary( _environment, VT_FLOAT, "(float)" );
92#if defined(__c128z__) || defined(__vg5000__) || defined(__zx__) || \
93 defined(__coleco__) || defined(__cpc__) || defined(__sc3000__) || \
94 defined(__sc3000__) || defined(__sg1000__) || defined(__msx1__) || \
95 defined(__gb__)
96 variable_store_float( _environment, pi->name, M_PI );
97#else
98 cpu_move_32bit( _environment, "PI", pi->realName );
99#endif
100 Variable * d180 = variable_temporary( _environment, VT_FLOAT, "(d180)" );
101 variable_store_float( _environment, d180->name, 180.0 );
102 Variable * radianAngle = variable_temporary( _environment, VT_FLOAT, "(tan)");
103 cpu_float_single_mul( _environment, angle->realName, pi->realName, radianAngle->realName );
104 cpu_float_single_div( _environment, radianAngle->realName, d180->realName, radianAngle->realName );
105 cpu_float_single_tan( _environment, radianAngle->realName, result->realName );
106 } else {
107 cpu_float_single_tan( _environment, angle->realName, result->realName );
108 }
109 break;
110 }
111
112 return result;
113
114}
void cpu_float_fast_tan(Environment *_environment, char *_angle, char *_result)
Definition 6309.c:7287
void cpu_float_fast_div(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6309.c:7228
void cpu_move_32bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 32 bit
Definition 6309.c:2520
void cpu_float_fast_mul(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6309.c:7207
void cpu_float_single_div(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6309.c:7232
void cpu_float_single_mul(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6309.c:7211
void cpu_float_single_tan(Environment *_environment, char *_angle, char *_result)
Definition 6309.c:7291
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
Variable * variable_store_float(Environment *_environment, char *_destination, double _value)
Store a string to a variable.
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
Variable * fp_tan(Environment *_environment, char *_angle)
Definition fp_tan.c:62
FloatType floatType
Definition ugbc.h:2400
FloatTypeAngle angle
Definition ugbc.h:869
FloatTypePrecision precision
Definition ugbc.h:991
char * name
Definition ugbc.h:979
char * realName
Definition ugbc.h:982
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_FLOAT
Definition ugbc.h:522
@ FT_FAST
Definition ugbc.h:854
@ FT_SINGLE
Definition ugbc.h:855
@ FT_DEGREE
Definition ugbc.h:862