MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / evlMod

Function evlMod

src/jrd/SysFunction.cpp:5599–5659  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5597
5598
5599dsc* evlMod(thread_db* tdbb, const SysFunction*, const NestValueArray& args,
5600 impure_value* impure)
5601{
5602 fb_assert(args.getCount() == 2);
5603
5604 Request* request = tdbb->getRequest();
5605
5606 const dsc* value1 = EVL_expr(tdbb, request, args[0]);
5607 if (request->req_flags & req_null) // return NULL if value1 is NULL
5608 return NULL;
5609
5610 const dsc* value2 = EVL_expr(tdbb, request, args[1]);
5611 if (request->req_flags & req_null) // return NULL if value2 is NULL
5612 return NULL;
5613
5614 EVL_make_value(tdbb, value1, impure);
5615 impure->vlu_desc.dsc_scale = 0;
5616
5617 if (impure->vlu_desc.dsc_dtype == dtype_int128)
5618 {
5619 const Int128 divisor = MOV_get_int128(tdbb, value2, 0);
5620 Int128 cmp0;
5621 cmp0.set(0, 0);
5622
5623 if (divisor == cmp0)
5624 status_exception::raise(Arg::Gds(isc_arith_except) << Arg::Gds(isc_exception_integer_divide_by_zero));
5625
5626 impure->vlu_misc.vlu_int128 = MOV_get_int128(tdbb, value1, 0).mod(divisor);
5627
5628 return &impure->vlu_desc;
5629 }
5630
5631 const SINT64 divisor = MOV_get_int64(tdbb, value2, 0);
5632
5633 if (divisor == 0)
5634 status_exception::raise(Arg::Gds(isc_arith_except) << Arg::Gds(isc_exception_integer_divide_by_zero));
5635
5636 const SINT64 result = MOV_get_int64(tdbb, value1, 0) % divisor;
5637
5638 switch (impure->vlu_desc.dsc_dtype)
5639 {
5640 case dtype_short:
5641 impure->vlu_misc.vlu_short = (SSHORT) result;
5642 break;
5643
5644 case dtype_long:
5645 impure->vlu_misc.vlu_long = (SLONG) result;
5646 break;
5647
5648 case dtype_int64:
5649 impure->vlu_misc.vlu_int64 = result;
5650 break;
5651
5652 default:
5653 impure->vlu_misc.vlu_int64 = result;
5654 impure->vlu_desc.makeInt64(0, &impure->vlu_misc.vlu_int64);
5655 break;
5656 }

Callers

nothing calls this directly

Calls 11

EVL_exprFunction · 0.85
EVL_make_valueFunction · 0.85
MOV_get_int128Function · 0.85
raiseFunction · 0.85
GdsClass · 0.85
MOV_get_int64Function · 0.85
makeInt64Method · 0.80
getCountMethod · 0.45
getRequestMethod · 0.45
setMethod · 0.45
modMethod · 0.45

Tested by

no test coverage detected