Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
FuzzQuadRoots.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "fuzz/Fuzz.h"
11#include "src/base/SkCubics.h"
12#include "src/base/SkQuads.h"
13#include "src/base/SkUtils.h"
14
15#include <cmath>
16
17static void fuzz_quad_real_roots(double A, double B, double C) {
18 double roots[2];
19 const int numSolutions = SkQuads::RootsReal(A, B, C, roots);
20 SkASSERT_RELEASE(numSolutions >= 0 && numSolutions <= 2);
21 for (int i = 0; i < numSolutions; i++) {
22 SkASSERT_RELEASE(std::isfinite(roots[i]));
23 // You may be tempted to add assertions that plug the provided solutions into
24 // the quadratic equation and verify that the result is zero. Be advised
25 // that the fuzzer is very good at finding float values that result in
26 // seemingly arbitrarily large errors, due to the imprecision of floating
27 // point math. Unless the input range is sufficiently small, such an
28 // effort seems fruitless.
29 }
30 if (numSolutions == 2) {
31 // Roots should not be duplicated
33 }
34}
35
36DEF_FUZZ(QuadRoots, fuzz) {
37 double A, B, C;
38 fuzz->next(&A);
39 fuzz->next(&B);
40 fuzz->next(&C);
41
42 // Uncomment for easy test case creation
43// SkDebugf("A %16e (0x%lx) B %16e (0x%lx) C %16e (0x%lx)\n",
44// A, sk_bit_cast<uint64_t>(A), B, sk_bit_cast<uint64_t>(B),
45// C, sk_bit_cast<uint64_t>(C));
46
48}
static void fuzz_quad_real_roots(double A, double B, double C)
#define DEF_FUZZ(name, f)
Definition Fuzz.h:156
#define SkASSERT_RELEASE(cond)
Definition SkAssert.h:100
bool sk_doubles_nearly_equal_ulps(double a, double b, uint8_t maxUlpsDiff=16)
static int RootsReal(double A, double B, double C, double solution[2])
Definition SkQuads.cpp:135
#define C(TEST_CATEGORY)
Definition colrv1.cpp:247
#define B