urbit/j/5/rd.c

268 lines
4.2 KiB
C
Raw Normal View History

/* j/5/aes.c
**
** This file is in the public domain.
*/
#include "all.h"
2014-09-04 07:10:43 +04:00
union doub {
double d;
c3_d c;
};
/* functions
*/
2014-06-04 23:16:15 +04:00
/* sun
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cqer_sun(u3_atom a)
2014-06-04 23:16:15 +04:00
{
union doub b;
2014-09-06 00:13:24 +04:00
b.d = (double) u3_cr_chub(0, a);
2014-06-05 06:46:12 +04:00
2014-09-06 00:13:24 +04:00
return u3_ci_chubs(1, &b.c);
2014-06-04 23:16:15 +04:00
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cwer_sun(u3_noun cor)
2014-06-04 23:16:15 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun a;
2014-06-04 23:16:15 +04:00
2014-09-06 00:13:24 +04:00
if (u3_no == u3_cr_mean(cor, u3_cv_sam, &a, 0)
|| u3_no == u3ud(a)) {
return u3_cm_bail(c3__exit);
2014-06-04 23:16:15 +04:00
}
else {
2014-09-06 00:13:24 +04:00
return u3_cqer_sun(a);
2014-06-04 23:16:15 +04:00
}
}
/* mul
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cqer_mul(u3_atom a, u3_atom b)
{
union doub c, d, e;
2014-09-06 00:13:24 +04:00
c.c = u3_cr_chub(0, a);
d.c = u3_cr_chub(0, b);
e.d = c.d * d.d;
2014-06-05 06:46:12 +04:00
2014-09-06 00:13:24 +04:00
return u3_ci_chubs(1, &e.c);
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cwer_mul(u3_noun cor)
{
2014-09-06 00:13:24 +04:00
u3_noun a, b;
2014-09-06 00:13:24 +04:00
if ( u3_no == u3_cr_mean(cor, u3_cv_sam_2, &a, u3_cv_sam_3, &b, 0) ||
u3_no == u3ud(a) ||
u3_no == u3ud(b) )
{
2014-09-06 00:13:24 +04:00
return u3_cm_bail(c3__exit);
}
else {
2014-09-06 00:13:24 +04:00
return u3_cqer_mul(a, b);
}
}
/* div
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cqer_div(u3_atom a, u3_atom b)
{
union doub c, d, e;
2014-09-06 00:13:24 +04:00
c.c = u3_cr_chub(0, a);
d.c = u3_cr_chub(0, b);
e.d = c.d / d.d;
2014-06-05 06:46:12 +04:00
2014-09-06 00:13:24 +04:00
return u3_ci_chubs(1, &e.c);
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cwer_div(u3_noun cor)
{
2014-09-06 00:13:24 +04:00
u3_noun a, b;
2014-09-06 00:13:24 +04:00
if ( u3_no == u3_cr_mean(cor, u3_cv_sam_2, &a, u3_cv_sam_3, &b, 0) ||
u3_no == u3ud(a) ||
u3_no == u3ud(b) )
{
2014-09-06 00:13:24 +04:00
return u3_cm_bail(c3__exit);
}
else {
2014-09-06 00:13:24 +04:00
return u3_cqer_div(a, b);
}
}
/* add
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cqer_add(u3_atom a, u3_atom b)
{
union doub c, d, e;
2014-09-06 00:13:24 +04:00
c.c = u3_cr_chub(0, a);
d.c = u3_cr_chub(0, b);
e.d = c.d + d.d;
2014-06-05 06:46:12 +04:00
2014-09-06 00:13:24 +04:00
return u3_ci_chubs(1, &e.c);
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cwer_add(u3_noun cor)
{
2014-09-06 00:13:24 +04:00
u3_noun a, b;
2014-09-06 00:13:24 +04:00
if ( u3_no == u3_cr_mean(cor, u3_cv_sam_2, &a, u3_cv_sam_3, &b, 0) ||
u3_no == u3ud(a) ||
u3_no == u3ud(b) )
{
2014-09-06 00:13:24 +04:00
return u3_cm_bail(c3__exit);
}
else {
2014-09-06 00:13:24 +04:00
return u3_cqer_add(a, b);
}
}
2014-06-02 23:13:58 +04:00
/* sub
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cqer_sub(u3_atom a, u3_atom b)
2014-06-02 23:13:58 +04:00
{
union doub c, d, e;
2014-09-06 00:13:24 +04:00
c.c = u3_cr_chub(0, a);
d.c = u3_cr_chub(0, b);
2014-06-02 23:13:58 +04:00
e.d = c.d - d.d;
2014-06-05 06:46:12 +04:00
2014-09-06 00:13:24 +04:00
return u3_ci_chubs(1, &e.c);
2014-06-02 23:13:58 +04:00
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cwer_sub(u3_noun cor)
2014-06-02 23:13:58 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun a, b;
2014-06-02 23:13:58 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_no == u3_cr_mean(cor, u3_cv_sam_2, &a, u3_cv_sam_3, &b, 0) ||
u3_no == u3ud(a) ||
u3_no == u3ud(b) )
2014-06-02 23:13:58 +04:00
{
2014-09-06 00:13:24 +04:00
return u3_cm_bail(c3__exit);
2014-06-02 23:13:58 +04:00
}
else {
2014-09-06 00:13:24 +04:00
return u3_cqer_sub(a, b);
2014-06-02 23:13:58 +04:00
}
}
/* lte
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cqer_lte(u3_atom a, u3_atom b)
{
union doub c, d;
2014-09-06 00:13:24 +04:00
c.c = u3_cr_chub(0, a);
d.c = u3_cr_chub(0, b);
2014-06-05 06:46:12 +04:00
2014-09-06 00:13:24 +04:00
return u3_say(c.d <= d.d);
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cwer_lte(u3_noun cor)
{
2014-09-06 00:13:24 +04:00
u3_noun a, b;
2014-09-06 00:13:24 +04:00
if ( u3_no == u3_cr_mean(cor, u3_cv_sam_2, &a, u3_cv_sam_3, &b, 0) ||
u3_no == u3ud(a) ||
u3_no == u3ud(b) )
{
2014-09-06 00:13:24 +04:00
return u3_cm_bail(c3__exit);
}
else {
2014-09-06 00:13:24 +04:00
return u3_cqer_lte(a, b);
}
}
/* lth
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cqer_lth(u3_atom a, u3_atom b)
{
union doub c, d;
2014-09-06 00:13:24 +04:00
c.c = u3_cr_chub(0, a);
d.c = u3_cr_chub(0, b);
2014-06-05 06:46:12 +04:00
2014-09-06 00:13:24 +04:00
return u3_say(c.d < d.d);
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cwer_lth(u3_noun cor)
{
2014-09-06 00:13:24 +04:00
u3_noun a, b;
2014-09-06 00:13:24 +04:00
if ( u3_no == u3_cr_mean(cor, u3_cv_sam_2, &a, u3_cv_sam_3, &b, 0) ||
u3_no == u3ud(a) ||
u3_no == u3ud(b) )
{
2014-09-06 00:13:24 +04:00
return u3_cm_bail(c3__exit);
}
else {
2014-09-06 00:13:24 +04:00
return u3_cqer_lth(a, b);
}
}
/* gte
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cqer_gte(u3_atom a, u3_atom b)
{
union doub c, d;
2014-09-06 00:13:24 +04:00
c.c = u3_cr_chub(0, a);
d.c = u3_cr_chub(0, b);
2014-06-05 06:46:12 +04:00
2014-09-06 00:13:24 +04:00
return u3_say(c.d >= d.d);
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cwer_gte(u3_noun cor)
{
2014-09-06 00:13:24 +04:00
u3_noun a, b;
2014-09-06 00:13:24 +04:00
if ( u3_no == u3_cr_mean(cor, u3_cv_sam_2, &a, u3_cv_sam_3, &b, 0) ||
u3_no == u3ud(a) ||
u3_no == u3ud(b) )
{
2014-09-06 00:13:24 +04:00
return u3_cm_bail(c3__exit);
}
else {
2014-09-06 00:13:24 +04:00
return u3_cqer_gte(a, b);
}
}
/* gth
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cqer_gth(u3_atom a, u3_atom b)
{
union doub c, d;
2014-09-06 00:13:24 +04:00
c.c = u3_cr_chub(0, a);
d.c = u3_cr_chub(0, b);
2014-06-05 06:46:12 +04:00
2014-09-06 00:13:24 +04:00
return u3_say(c.d > d.d);
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cwer_gth(u3_noun cor)
{
2014-09-06 00:13:24 +04:00
u3_noun a, b;
2014-09-06 00:13:24 +04:00
if ( u3_no == u3_cr_mean(cor, u3_cv_sam_2, &a, u3_cv_sam_3, &b, 0) ||
u3_no == u3ud(a) ||
u3_no == u3ud(b) )
{
2014-09-06 00:13:24 +04:00
return u3_cm_bail(c3__exit);
}
else {
2014-09-06 00:13:24 +04:00
return u3_cqer_gth(a, b);
}
}