Skip to content

Commit

Permalink
Put golden ratio for ca into its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
Raoul Bourquin committed May 26, 2023
1 parent e886e87 commit 46762a1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions doc/source/ca.rst
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ Special values
Sets *res* to Euler's constant `\gamma`. This creates an element
of the (transcendental?) number field `\mathbb{Q}(\gamma)`.

.. function:: void ca_phi(ca_t res, ca_ctx_t ctx)

Sets *res* to the golden ratio `\varphi`.

.. function:: void ca_unknown(ca_t res, ca_ctx_t ctx)

Sets *res* to the meta-value *Unknown*.
Expand Down
2 changes: 2 additions & 0 deletions src/ca.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ void ca_pi(ca_t res, ca_ctx_t ctx);
void ca_pi_i(ca_t res, ca_ctx_t ctx);
void ca_euler(ca_t res, ca_ctx_t ctx);

void ca_phi(ca_t res, ca_ctx_t ctx);

void ca_unknown(ca_t x, ca_ctx_t ctx);

void ca_undefined(ca_t x, ca_ctx_t ctx);
Expand Down
21 changes: 21 additions & 0 deletions src/ca/phi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright (C) 2020 Fredrik Johansson
Copyright (C) 2022 Raoul Bourquin
This file is part of Calcium.
Calcium is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. See <http://www.gnu.org/licenses/>.
*/

#include "ca.h"

void
ca_phi(ca_t res, ca_ctx_t ctx)
{
ca_sqrt_ui(res, 5, ctx);
ca_add_ui(res, res, 1, ctx);
ca_div_ui(res, res, 2, ctx);
}
4 changes: 1 addition & 3 deletions src/ca/set_fexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ _ca_set_fexpr(ca_t res, fexpr_vec_t inputs, ca_vec_t outputs, const fexpr_t expr
ca_euler(res, ctx);
return 1;
case FEXPR_GoldenRatio:
ca_sqrt_ui(res, 5, ctx);
ca_add_ui(res, res, 1, ctx);
ca_div_ui(res, res, 2, ctx);
ca_phi(res, ctx);
return 1;
case FEXPR_Infinity:
ca_pos_inf(res, ctx);
Expand Down

0 comments on commit 46762a1

Please sign in to comment.