fix compilation error and fix stddev calculation
This commit is contained in:
4
Makefile
4
Makefile
@ -1,6 +1,6 @@
|
||||
NAME = ft_ping
|
||||
CC=cc
|
||||
FLAGS=-Werror -Wextra -Wall -g -Wno-unused-result -lm
|
||||
FLAGS=-Werror -Wextra -Wall -g -Wno-unused-result
|
||||
|
||||
SRCS_DIR = srcs
|
||||
OBJS_DIR = .objs
|
||||
@ -18,7 +18,7 @@ OBJS = $(addprefix $(OBJS_DIR)/,$(SRCS:.c=.o))
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJS_DIR) $(OBJS)
|
||||
$(CC) $(FLAGS) $(OBJS) -o $@
|
||||
$(CC) $(FLAGS) $(OBJS) -o $@ -lm
|
||||
|
||||
$(OBJS_DIR):
|
||||
mkdir $(OBJS_DIR)
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/26 19:54:25 by tomoron #+# #+# */
|
||||
/* Updated: 2025/05/02 01:04:29 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/05/02 23:55:50 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -50,6 +50,8 @@ void ping_end_print(t_settings *set, char *host, t_stats *stats)
|
||||
|
||||
(void)set;
|
||||
stddev = sqrt(stats->sqr_diff / (stats->received - 1));
|
||||
if(isnan(stddev) || isinf(stddev))
|
||||
stddev = 0.0f;
|
||||
printf("--- %s ping statistics ---\n", host);
|
||||
percent = ((double)stats->sent / 100) * stats->received;
|
||||
printf("%lu packets transmitted, %lu packets received, %d%% packet loss\n", stats->sent, stats->received, percent);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/01 17:41:42 by tomoron #+# #+# */
|
||||
/* Updated: 2025/05/02 01:03:15 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/05/02 23:53:28 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -18,15 +18,13 @@ void update_stats(t_stats *stats, double time)
|
||||
|
||||
stats->received++;
|
||||
tmp = 0;
|
||||
if(stats->prev)
|
||||
tmp = time - stats->avg;
|
||||
tmp = time - stats->avg;
|
||||
stats->min = MIN(stats->min, time);
|
||||
if(stats->min == 0)
|
||||
stats->min = time;
|
||||
stats->max = MAX(stats->max, time);
|
||||
stats->avg += (time - stats->avg) / stats->received;
|
||||
if(stats->prev)
|
||||
stats->sqr_diff += tmp * stats->avg;
|
||||
stats->sqr_diff += tmp * stats->avg;
|
||||
stats->prev = time;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user