data_structures
src
types
type_float.c
Go to the documentation of this file.
1
/* ************************************************************************** */
3
/* */
4
/* ::: :::::::: */
5
/* type_float.c :+: :+: :+: */
6
/* +:+ +:+ +:+ */
7
/* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8
/* +#+#+#+#+#+ +#+ */
9
/* Created: 2020/07/16 22:27:52 by unite #+# #+# */
10
/* Updated: 2020/09/04 22:54:38 by unite ### ########.fr */
11
/* */
12
/* ************************************************************************** */
13
14
#include "
types.h
"
15
16
void
*type_float_copy(
const
void
*f)
17
{
18
float
*copy;
19
20
if
(!f || !(copy = malloc(
sizeof
(
float
))))
21
return
(NULL);
22
*copy = *(
float
*)f;
23
return
(copy);
24
}
25
26
int
type_float_cmp(
const
void
*f1,
const
void
*f2)
27
{
28
if
(!f1 && !f2)
29
return
(0);
30
if
(!f1)
31
return
(-1);
32
if
(!f2)
33
return
(1);
34
if
(*(
float
*)f1 < *(
float
*)f2)
35
return
(-1);
36
if
(*(
float
*)f1 > *(
float
*)f2)
37
return
(1);
38
return
(0);
39
}
40
41
size_t
type_float_hash(
const
void
*f,
size_t
M)
42
{
43
if
(!f)
44
return
(0);
45
return
(*(
size_t
*)f % M);
46
}
47
48
static
const
t_type
g_type_float_struct = {
49
.
name
=
"float"
,
50
.copy = &type_float_copy,
51
.del = &free,
52
.cmp = &type_float_cmp,
53
.hash = &type_float_hash,
54
};
55
56
const
t_type
*
g_type_float
= &g_type_float_struct;
s_type::name
char * name
The name of a datatype as a string.
Definition:
types.h:49
types.h
g_type_float
const t_type * g_type_float
A representation of the float data type.
Definition:
type_float.c:56
s_type
A full representation of a data type, used to achieve polymorphism in the implementation of data stru...
Definition:
types.h:47
Generated by
1.8.16